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
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 ) ) {

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.