Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Dec 2010
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Regular expression in javascript for validation

    Regular Expressions provide a concise and flexible means for matching strings of text, such as particular characters, words, or patterns of characters. Regular expressions are used by many text editors, utilities, and programming languages to search and manipulate text based on patterns.
    Some of the symbols used in regular expressions are as follows;
    1) Vertical Bar (|) – This symbol is used to separate alternatives. Eg: rear|read can match both 'rear' and 'read'.
    2) Parenthesis (()) – Defines the scope and precedence of operators. Eg: rea(r|d) can match both 'rear' and 'read'.
    3) Quantification Tokens – There are a list of quantification tokens. Like:
    a) ? – This denotes that there may be one or zero instance of the symbol present. Eg: rea?d can match both 'read' and 'red'
    b) * – This denotes that there may be zero or more instance of the symbol present. Eg: rea*d can match all 'read','red','reaaad','reaad' etc.
    c) + – This denotes that there may be one or more instance of the symbol present. Eg: rea+d can match all 'read','reaaaad','reaaad','reaad' etc
    These expression are of great use when we are checking for a particular pattern through our program in .Net/Javacript. Like it may be useful in checking for any presence of special characters in a username field. It may also come to use when we are validating a mobile number field against the entry of any alphanumeric value. If we know how to use this feature properly, then the time taken for validating several fields may reduce by ½
    Let us now see that how we can validate several instances using Javascript Regular Expressions. Eg:
    1) Validate against any blank values:
    2) Validate against non – words:
    3) Validate against any blank values:
    4) Trimming a string – Removing its left and right blank spaces:
    5) Validating an Email Address:
    6) Validating a File Name:
    To go through a thorough tutorial on this topic along with a Video Tutorial to undesrtand in a better way, please visit;

    http://visiontechno.net/studymats/?cat=19

  • #2
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    18,011
    Thanks
    203
    Thanked 2,538 Times in 2,516 Posts
    Far better tutorials are already on this site at

    http://www.javascriptkit.com/javatutors/re.shtml

    http://www.javascriptkit.com/javatutors/redev.shtml


    Some people, when confronted with a problem, think "I know, I'll use regular expressions." Now they have two problems." — Jamie Zawinski.


  •  

    Posting Permissions

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