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

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  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.

Loading...
×
×
  • Create New...