mpriest88 Posted October 12, 2012 Report Share Posted October 12, 2012 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 Quote Link to comment Share on other sites More sharing options...
mpriest88 Posted October 12, 2012 Author Report Share Posted October 12, 2012 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 Quote Link to comment Share on other sites More sharing options...
falkencreative Posted October 12, 2012 Report Share Posted October 12, 2012 Sorry, which video are you following? A link to it would be helpful, so I can know exactly which tutorial you are following and how best to help you. Quote Link to comment Share on other sites More sharing options...
mpriest88 Posted October 13, 2012 Author Report Share Posted October 13, 2012 Sorry about that. Here they are: and Quote Link to comment Share on other sites More sharing options...
clickpencil Posted October 31, 2012 Report Share Posted October 31, 2012 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... Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.