Jump to content

[SOLVED] Validate Phone Number Length


ballouta

Recommended Posts

Hello

I have an html form named 'frm'

and a javascript functions for this form validation.

The validation is working on email address field, user name and password etc.. expect the phone number field named 'mobile'

The phone number should always be 6 digits.

 

this is part of my javascript file

 

 

function isReady() {

// check if the First Name is valid
    if (isProper(frm.fname.value) == false) {
        alert("Please enter your First Name");
        return false;
    }

// check if the email address is valid
    if (isEmail(frm.email.value) == false) {
        alert("Please enter a valid email address");
        return false;
    }

// check if the mobile is valid
    if (ismobile(frm.mobile.value) == false) {
        alert("Please enter a valid mobile number");
        return false;
     }
}//funncion isReady()

function ismobile(string) {
  if (string.length !=6)
      return false;
   return true;
}

 

The problem is in the function ismobile(string)

Please help

Link to comment
Share on other sites

script to validate 10 digit number

function validateNumber(field, msg, min, max) { 
if (!min) { min = 10 } 
if (!max) { max = 10 } 

if ( (parseInt(field.value) != field.value) ||  
       field.value.length < min || field.value.length > max) { 
alert(msg); 
field.focus(); 
field.select(); 
return false; 
} 

return true; 
}

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.