SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Enthusiast
    Join Date
    Nov 2008
    Posts
    35
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    form validation function not working

    hi all,

    I have a function that i call in the form onSubmit=" "
    the function works fine for the !="" condition but it does not work for the match condition.
    so form does not submit when input is empty
    form submits when the input is not valid.

    someone help please!

    <script>
    form name is: xxx

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

    function check(xxx)
    {
    if(document.xxx.field1.value!="" && document.xxx.field2.value!="" && document.xxx.field3.value!="" &&
    document.xxx.field1.value.match(alphaExp) && document.field2.value.match(alphaExp))
    { return true;
    }
    return false;
    }
    <script/>

    onSubmit="return check(xxx);"

  2. #2
    SitePoint Wizard silver trophy rushiku's Avatar
    Join Date
    Dec 2003
    Location
    A van down by the river
    Posts
    2,056
    Mentioned
    0 Post(s)
    Tagged
    1 Thread(s)
    This is technically a javascript question and doesn't belong here...

    But:

    match doesn't tell you if your string matches the regex, it returns the string if a portion of it matches the regex, as shown here

    You don't want numbers, apparently, so match for numbers and make sure you get null. (feels like a kludge, maybe someone else has a better suggestion)


Bookmarks

Posting Permissions

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