www.webdeveloper.com
Results 1 to 3 of 3

Thread: Form validation - regular expression alert/ submission error

Hybrid View

  1. #1
    Join Date
    Jul 2009
    Posts
    2

    Question Form validation - regular expression alert/ submission error

    Hi,

    I'm new to Javascript so I apologise if this is an obvious query..!

    I'm trying to incorporate a RegExp validation into the existing validate function but when a string that matches (I hope) re1 e.g. AB12 12AB is entered I still get the format alert and the form won't submit.

    Any ideas would be very gratefuly received!

    PHP Code:
    function validate(nodealerttxtre) {
              
    with (node)
                  if (
    value == null || value == "") {
                  
    alert(alerttxt); return false;
              }
              else if (
    re.test(node) ==false) {
                  
    alert(alerttxt" format"); return false;
              }
          }

          var 
    re1 = /^\D{1,2}\d{1,2}\s?\d{1,2}\D{1,2}$/;
          var 
    re2 = /^\D\w{4}\s?\w{5}\s?\w{3}\d[!|&|@|?]$/;

          function 
    validate_form(thisform) {
              
    with (thisform) {
                  if (
    validate(Node1"Please check Node1 field"re1) == false)
                  { 
    Node1.focus(); return false; }

                  if (
    validate(Node2"Please check Node2 number",re2) == false)
                  { 
    Node2.focus(); return false; }
                  else {
                      return 
    true;
                  }
              }
          }

    ...

    <
    form method="post" onsubmit="return validate_form(this)" action="http://...decode_form.cfm"

  2. #2
    Join Date
    Jun 2008
    Posts
    62
    shouldn't it be
    Code:
    re.test(value)

  3. #3
    Join Date
    Jul 2009
    Posts
    2
    I knew it would be obvious - thank you!

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles