It appears you have not yet registered with DEVPPL. To register please click here... (it's fast, easy and free!)

Forum

Log In Sponsors
Board index Programming JavaScript Forum

Javascript RegExp in Forms

Javascript RegExp in Forms

Postby ExpDisease on Thu Aug 26, 2010 12:34 pm

I cannot get the result right. I write area and phone by numbers but it still gives me error

Code: Select all
function validate_text(field,alerttext) {
   with(field) {
      
     var re = /[a-zA-Z]/g;
       if(re.test(field)) { return true;}else{alert(alerttext);return false;}
   }
}
function validate_number(field,alerttext){
     with(field) {
       
       var re = /[0-9]/g;
        if(re.test(field)) { return true;}else{alert(alerttext);return false;}
     }
}



function validateForm(thisForm){
   with(thisForm)
   {
      if(validate_number(area,"wrong area code") == false) {
      
         area.focus();return false;   
      }
      if(validate_number(phone,"wrong phone") == false) {
      
         phone.focus();return false;   
      }
      if(validate_text(name_surname,"wrong name") == false) {
      
         name_surname.focus();return false;   
      }

   }
}


Code: Select all
...<b>Name Surname :</b><input style="margin-left:10px;" type="text" name="name_surname"/>
<br /><br />
    <b>phone :</b><input type="text" style="margin-left:19px;" maxlength="4" size="4" name="area" />
-<input type="text" style="margin-left:5px;" maxlength="7" size="10" name="phone" /><br /><br />....
ExpDisease
 
Posts: 3
Joined: Thu Aug 26, 2010 12:32 pm

Who is online

Users browsing this forum: No registered users and 7 guests