Results 1 to 3 of 3

Thread: Help with form validation

  1. #1
    Join Date
    Jan 2007
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Help with form validation

    I have used http://www.dynamicdrive.com/dynamici...uiredcheck.htm
    to successfully validate parts of my form, just wondering if I could get some assistance in validating other functions such as valid email and is numeric?

    Thanks

  2. #2
    Join Date
    Sep 2006
    Location
    St. George, UT
    Posts
    2,769
    Thanks
    3
    Thanked 157 Times in 155 Posts

    Default

    For the email check, you could combine the script above with the following one:

    http://www.dynamicdrive.com/dynamicindex16/emailvalidate.htm


    As for the numbers, I believe there is a function call isNaN (is Not a Number). But not 100% on that.

    Hope this helps.
    "Computer games don't affect kids; I mean if Pac-Man affected us as kids, we'd all be running around in darkened rooms, munching magic pills and listening to repetitive electronic music." - Kristian Wilson, Nintendo, Inc, 1989
    TheUnlimitedHost | The Testing Site | Southern Utah Web Hosting and Design

  3. #3
    Join Date
    Jan 2007
    Posts
    31
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Here is my email validation function:
    Code:
    function echeck(str) {
    	var at = "@"
    	var dot = "."
    	var lat = str.indexOf(at)
    	var lstr = str.length
    	var ldot = str.indexOf(dot)
    	
    	if (str.indexOf(at) == -1){
    	   alert("Invalid E-mail ID")
    	   return false
    	}
    
    	if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
    	   alert("Invalid E-mail ID")
    	   return false
    	}
    
    	if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
    		alert("Invalid E-mail ID")
    		return false
    	}
    	 if (str.indexOf(at,(lat+1))!=-1){
    		alert("Invalid E-mail ID")
    		return false
    	 }
    	 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
    		alert("Invalid E-mail ID")
    		return false
    	 }
    	 if (str.indexOf(dot,(lat+2))==-1){
    		alert("Invalid E-mail ID")
    		return false
    	 }
    	 if (str.indexOf(" ")!=-1){
    		alert("Invalid E-mail ID")
    		return false
    	 }
    	 return true					
    }
    And for the numeric, as thetestingsite said, there is isNaN function in javascript:
    Code:
    if(isNaN(value)){
    alert('string');
    }else{
    alert('numeric');
    }

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •