Jump to content

[SOLVED] Script Modification


ballouta

Recommended Posts

Hello

I have this working validatiuon script.

 

<script type="text/javascript" language="Javascript" >
<!--
function verification()
{
if(document.registration.username.value == "")  {
   alert("Name required");
   document.registration.username.focus();
   return false;
  }
   else
if(document.registration.email.value == "") {
   alert("Email required");
   document.registration.email.focus();
   return false;
  }
  else
if(document.registration.email.value.indexOf('@') == -1) {
   alert("email not valid");
   document.registration.email.focus();
   return false;
  }
  else
if(document.registration.phone.value == "") {
   alert("Phone number is empty!");
   document.registration.phone.focus();
   return false;
  }
  else
if(document.registration.country.value == "") {
   alert("Country is empty!");
   document.registration.country.focus();
   return false;
  }
return true
}
//-->
</script>

 

i want to add more validation for the username (it should be between 4 and 12 characters)

is there better validation for the email address?

 

many thanks

Link to comment
https://forums.phpfreaks.com/topic/158894-solved-script-modification/
Share on other sites

Try these:

 

username:

 

username = document.registration.username;

if(username.value == "" OR username.length < 4 OR username.length > 12)  {

 

 

email:

 

pattern = /^([a-zA-Z0-9_-])+([\.a-zA-Z0-9_-])*@([a-zA-Z0-9_-])+(\.[a-zA-Z0-9]+)+$/;

if( !pattern.test( document.registration.email.value ) ) {

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.