If any illegal char exist do.. script help

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • wesselinbg
    New Member
    • Jul 2008
    • 1

    If any illegal char exist do.. script help

    Hello everyone! My name is Veselin and i'm php and mysql coder. But now i have big problems with one javascript that i want to create (maybe because i don't understand nothing from javascript :)). I want to create validate form that search for illegal chars. "." "/" "_" "\" ","

    My form name: MyJavaScriptFor m
    Field that i want to check: MyField


    I'm made this..

    [CODE=javascript]function check(){



    if ( i don't know what ){
    alert('There are illegals!');

    document.MyJava ScriptForm.MyFi eld.focus();
    return false;
    }



    document.MyJava ScriptForm.subm it();

    }[/CODE]


    Can you help me please? Thank you!
    Last edited by acoder; Jul 2 '08, 09:40 AM. Reason: Added [code] tags
  • acoder
    Recognized Expert MVP
    • Nov 2006
    • 16032

    #2
    Maybe you could just check for valid characters instead, but that really depends. If you only want alphanumeric characters, it's better to check against that instead of checking for every illegal character. However, if you want to allow any character except those that you've listed, then it makes more sense to check for those instead.

    Now, how do we validate? The first thing to do is to get the input field value. Then you can use regular expressions to check the value. See these links:
    Regular expressions are patterns used to match character combinations in strings. In JavaScript, regular expressions are also objects. These patterns are used with the exec() and test() methods of RegExp, and with the match(), matchAll(), replace(), replaceAll(), search(), and split() methods of String. This chapter describes JavaScript regular expressions. It provides a brief overview of each syntax element. For a detailed explanation of each one's semantics, read the regular expressions reference.

    Detailed description of the capabilities of the JavaScript RegExp Object, defined in the ECMA-262 standard.

    W3Schools offers free online tutorials, references and exercises in all the major languages of the web. Covering popular subjects like HTML, CSS, JavaScript, Python, SQL, Java, and many, many more.

    Comment

    Working...