Question:

JavaScript form validation help please?

by  |  earlier

0 LIKES UnLike

I am learning from:

http://www.tizag.com/javascriptT/javascriptform.php

At the very end, (last example) the form works, but how do i get it to accept spaces for address and Zip fields?

Thanks in advance

 Tags:

   Report

1 ANSWERS


  1. You are right, that form works but it also doesn't work! The address field won't accept blank spaces or the # sign which I use a lot because I live in an apartment - N80 W 140 my avenue #5). It also does not check the length of the zip code. I actually would not allow blank spaces in the zip code, but I would limit the length of it to 5 (numeric) characters.

    Changes I have made in my testing to make it work for me:

    change this error message in the formValidator() function:

    if(isAlphanumeric(addr, "Numbers and Letters and # Sign Only for Address"))

    and change this error message also in the formValidator() function to denote 5 digit entry:

    if(isNumeric(zip, "Please enter a valid 5 digit zip code"))

    then in the isNumeric(elem,helperMsg) function add an && to the if statement to set the length to exactly 5:

    if (elem.value.match(numericExpression) && elem.value.length == 5)

    then in the isAlphanumeric(elem, helperMsg) function allow for white space and the # sign by changing the regular expression in the alphaExp variable statement by adding a single blank space in the allowed characters set to allow white space and # to allow that sign in to the character set:

    var alphaExp = /^[0-9a-zA-Z# ]+$/;

Question Stats

Latest activity: earlier.
This question has 1 answers.

BECOME A GUIDE

Share your knowledge and help people by answering questions.