Results 1 to 5 of 5

Thread: Invalid Characters.

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Mar 2002
    Location
    Malaysia
    Posts
    345

    Invalid Characters.

    I want to write a Javascript function so that the user is barred from entering invalid characters like"!@#$%^&*()_+" in a sensitive field like User Name.


    Please Help.
    Thanks.

  2. #2
    Good Ol' Platypus Sastraxi's Avatar
    Join Date
    Jan 2000
    Location
    Ontario, Canada
    Posts
    5,134
    You can do this during validation of a form. Just see if any of them are in the string and if it is, cancel the submission of the form.
    All contents of the above post that aren't somebody elses are mine, not the property of some media corporation.
    (Just a heads-up)

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Mar 2002
    Location
    Malaysia
    Posts
    345
    I haven't done much of javascript. Can i get the syntaxes pls.
    Thanks.

  4. #4
    Frenzied Member DeadEyes's Avatar
    Join Date
    Jul 2002
    Posts
    1,196
    Code:
    //param val is string to check ie username
    function isAlphaNumeric(val){
    	var str = new String(val);
    	return (str.search(/\W/)=="-1")?true:false;
    }
    Add an onClick event to the login button and call the function
    if it's true and other validation ok then submit the form

  5. #5
    Frenzied Member Rick Bull's Avatar
    Join Date
    Apr 2002
    Location
    England
    Posts
    1,444
    Add it to the onsubmit of the form instead, it's the better place to put it (unless you have two submit buttons and you don't need the validation for one)

Posting Permissions

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



Click Here to Expand Forum to Full Width