Validating input in java script
Incase you didn't provide information in the format specified by the form field or leave it empty, the message will appear and form cannot be submitted until you get it right.
Next, we use regular expression and the test() method to check the field for a compliance.
Also we will use trim() function that will trim leading whitespace off the string.
validate Email ( ) Next we want to see if the email address the user entered is real.
This means that the input data must contain at least an @ sign and a dot (.).
The regular expression is used to find the characters and then replace them with empty spaces.
Unwanted parentheses surrounding area codes or telephone numbers, can be removed using regular expression and method replace() The regular expression searches for one or more parentheses, spaces or dashes , globally.
validate Password ( ) The function below checks the password field for blankness and allow only letters and numbers - no underscopes this time.
The demo below , uses a function to check if value in the form field is empty or null.
If its not blank, the function returns an empty string.
validate Username ( ) The function below checks if the user entered anything at all in the username field.
This wont be perfect validation it is possible to slip not compliant addresses by it but it's normally good enough.