www.webdeveloper.com
Results 1 to 3 of 3

Thread: how to allow whitespace in my javascript validation

  1. #1
    Join Date
    Apr 2007
    Posts
    3

    how to allow whitespace in my javascript validation

    Hi all
    I need to allow whitespace in my javascript validation in each word.
    I don't know how to do the same can anybody help me.
    I have written the javascript, in this code whitespace is not allowing right now
    can any body help me regarding this.
    here is my code
    //

    function isCharsInBag (s, bag)
    {
    var i;
    for (i = 0; i < s.length; i++)
    {
    // Check that current character isn't whitespace.
    var c = s.charAt(i);
    if (bag.indexOf(c) == -1) return false;
    }
    return true;
    }


    if (isWhitespace(document.form1.partno.value))

    {
    Q += " Supplier Part Number\n";
    }
    if (!isCharsInBag(document.form1.partno.value, "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz " ))
    {
    errMesg += " Enter Alpha Numeric Value For Supplier Part Number\n";
    }

    //

    thanks

  2. #2
    Join Date
    Mar 2007
    Location
    Nagpur (India)
    Posts
    107
    Try the following regex.

    function JS_Validator(f) {
    if (f.elements[0].value.length < 1) {
    alert("Enter Alpha Numeric Value For Supplier Part Number.");
    f.elements[0].focus();
    return(false);
    }
    if (window.RegExp) {
    var reg = new RegExp("^([a-zA-Z0-9 ])*$", "g");
    if (!reg.test(f.elements[1].value)) {
    alert("Enter Alpha Numeric Value For Supplier Part Number");
    f.elements[1].focus();
    return(false);
    }
    }
    }

  3. #3
    Join Date
    Mar 2006
    Posts
    62
    Try this :

    Code:
    var name = document.form1.partno.value;
    if (!name.match(/^[a-zA-Z0-9 ]+$/))
    {
    errMesg += " Enter Alpha Numeric Value For Supplier Part Number\n";
    }

Thread Information

Users Browsing this Thread

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

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