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
https://forums.phpfreaks.com/topic/109865-solved-validate-phone-number-length/
Share on other sites

Hi

I replaced the function with this one but the form still NOT validating the mobile field.

 

http://www.gsclonline.org/register.htm

 

Another question: Does this function validates the input if it is numbers or not?

 

thanks alot

 

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; 
}

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.