Jump to content

Recommended Posts

Posted

I am trying to learn Javascript and happened across the video "PHP & Form Validation". All works except the phone number field. It is set as required and to be formatted as 000-000-0000. If it's left blank I get a message "This field is required". Then if I go back and enter just 1 digit it's accepted, instead of saying "Please enter a valid phone number". I have no idea what could be wrong or where to start looking to fix the issue. Can someone please suggest things to checked. I want to fix it myself, so just some tips on what to check will be greatly appreciated. Thank you

Posted

I think I figured it out. I went through the validate.js file and discovered the class name should have been required number, instead of just required. Now my next question is how do I get the dashes to display? Example: user enters 1231231234 and when they go to the next field it changes to 123-123-1234

  • 3 weeks later...
Posted

Try this script..

I just commented out action you will take after your phone has been validated or not.

 

 

function validate (phone) {

var regex = /^\+(?:[0-9] ?){6,14}[0-9]$/;

 

if (regex.test(phone)) {

// Valid international phone number

} else {

// Invalid international phone number

}

}

 

I hope this will help you...

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...