check form

Javascript coding ..

Moderators: macek, egami, gesf

cermin_mata
New php-forum User
New php-forum User
Posts: 5
Joined: Thu Jan 16, 2003 7:59 am
Contact:

check form

Postby cermin_mata » Sat Feb 01, 2003 4:13 am

<!--
function validate(input) {
if (input.name.value=="") {
alert("Please complete the name field.");
return false;
}
if (input.email.value=="") {
alert("Please complete the email field.");
return false;
}
if (input.phone.value=="") {
alert("Please complete the phone field.");
return false;
}
}
//-->

</script>

i put this file top of my form to check if my form already fill out or not...but i don't know how to make it find email and phone is not real valid..

i mean..if people put "abcdefghij" in email field it will not process..it will say.."please put real email" that contain abc@abc.com

and if people put "abcdefghij" in email field it will not process..it will say.."please put real phone" that contain 123456789(number only)

please help me..

User avatar
Redcircle
Moderator
Moderator
Posts: 830
Joined: Tue Jan 21, 2003 10:42 pm
Location: Michigan USA
Contact:

Postby Redcircle » Sun Feb 02, 2003 1:45 pm

Code: Select all

<script>
<!--

// Email Validation. Written by PerlScriptsJavaScripts.com

function check_email(e) {
ok = "1234567890qwertyuiop[]asdfghjklzxcvbnm.@-_QWERTYUIOPASDFGHJKLZXCVBNM";

for(i=0; i < e.length ;i++){
if(ok.indexOf(e.charAt(i))<0){
return (false);
}   
}

if (document.images) {
re = /(@.*@)|(\.\.)|(^\.)|(^@)|(@$)|(\.$)|(@\.)/;
re_two = /^.+\@(\[?)[a-zA-Z0-9\-\.]+\.([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$/;
if (!e.match(re) && e.match(re_two)) {
return (-1);      
}

}

}
function CheckPhoneNumber(TheNumber) {
   var valid = 1
   var GoodChars = "0123456789()-+ "
   var i = 0
   if (TheNumber=="") {
      // Return false if number is empty
      valid = 0
   }
   for (i =0; i <= TheNumber.length -1; i++) {
      if (GoodChars.indexOf(TheNumber.charAt(i)) == -1) {
// Note: Remove the comments from the following line to see this
// for loop in action.
// alert(TheNumber.charAt(i) + " is no good.")
         valid = 0
      } // End if statement
   } // End for loop
   return valid
}

// -->
</script>


Return to “JavaScript”

Who is online

Users browsing this forum: No registered users and 1 guest