Validating phone numbers in php

10 Jul

Well with a master form Validator function we can do just that.Inside each string is a function called match that you can use to see if the string matches a certain regular expression.We accessed this function like so: elem.value.match(expressionhere).To be sure that someone has actually selected a choice from an HTML select input you can use a simple trick of making the first option as helpful prompt to the user and a red flag to you for your validation code.By making the first option of your select input something like "Please Choose" you can spur the user to both make a selection and allow you to check to see if the default option "Please Choose" is still selected when the submit the form.

As long as elem.value.length isn't 0 then it's not empty and we return true, otherwise we send an alert to the user with a helper Msg to inform them of their error and return false.