21 users online (0 members and 21 guests)  


  Results 1 to 4 of 4

Related

  1. html validation problem    Forum: HTML Forum
    Replies: 2
  2. Replies: 4
  3. Help with Javascript form validation please!!    Forum: Javascript Forum
    Replies: 2
  4. Form Validation Help Needed Please    Forum: Javascript Forum
    Replies: 1
  5. Form validation - please help!    Forum: Javascript Forum
    Replies: 3
  1. #1
    snowman's Avatar
    New User

    Status
    Offline
    Join Date
    Mar 2004
    Posts
    3

    Problem With form validation of Postal Code

    Hello all .. I am confused as to why this function will not do a validation of the Postal Code?

    function postalCheck()
    {
    var postalPattern ="^[A-Z][0-9][A-Z](|-)[0-9][A-Z][0-9]$";
    var postalRegExp = new RegExp(postalPattern);
    if (document.myform.postal.value =="")
    {
    alert(" the field must be entered ");
    }
    if (document.myform.postal.value !=="postalPattern" )
    {
    alert( "the field is invalid");
    }
    }

  2. #2
    QuietDean's Avatar
    Administrator

    Status
    Offline
    Join Date
    Oct 2000
    Location
    Bournemouth, UK
    Posts
    2,662
    Hiya, welcome to the forums.

    I amended the function to look like this -

    Code:
    function postalCheck()
    {
    var postalPattern = /^[A-Z][0-9][A-Z](|-)[0-9][A-Z][0-9]$/;
    var postalRegExp = new RegExp(postalPattern);
    if (document.myform.postal.value =="")
    {
    alert(" the field must be entered ");
    }
    if (postalRegExp.test(document.myform.postal.value) == false )
    {
    alert( "the field is invalid");
    }
    }
    Which, for me, now validates according to the regexp specified.

    It does not validate my Postal Code, but I am in the UK so my format is (where A is letter and n is number) AAnnnEn
    If one of our members helps you, please click the icon to add to their reputation!
    No support via email or private message - use the forums!
    Before you ask, have you Searched?

  3. #3
    snowman's Avatar
    New User

    Status
    Offline
    Join Date
    Mar 2004
    Posts
    3

    Thank you

    Thank you for welcoming me to the forum
    and thank you for the information i do appricate it

    Derek
    Quote Originally Posted by QuietDean
    Hiya, welcome to the forums.

    I amended the function to look like this -

    Code:
    function postalCheck()
    {
    var postalPattern = /^[A-Z][0-9][A-Z](|-)[0-9][A-Z][0-9]$/;
    var postalRegExp = new RegExp(postalPattern);
    if (document.myform.postal.value =="")
    {
    alert(" the field must be entered ");
    }
    if (postalRegExp.test(document.myform.postal.value) == false )
    {
    alert( "the field is invalid");
    }
    }
    Which, for me, now validates according to the regexp specified.

    It does not validate my Postal Code, but I am in the UK so my format is (where A is letter and n is number) AAnnnEn

  4. #4
    darlenehill19's Avatar
    New User

    Status
    Offline
    Join Date
    Feb 2011
    Posts
    1

    Exclamation Re: Problem With form validation of Postal Code

    the misery has not yet ended my friend!!
    think about validating 6 digits postal codes
    i am searching the solution; my work extended;
    any advice?? anybody working on same or not
    Last edited by HTML; 02-08-2011 at 10:25 AM.



Tags for this Thread