js common verify rule using regular expressions cheatsheet

When we design a form, the data must be verifyed before the user submit. Regular expressions can help us to do this task and impove the customer experience.

Here is a list of most used rules in a validator.

How to use 


    var inputValue = "",// 
        expr = /^[0-9]+$/; 
    if(expr.test(inputValue)){ // expr.exec(string)
        //not allow

/^[0-9]*$/    // allow only numeric
/^d{n}$/      // only n digits, use occasion: Credit card number verify
/^d{n,}$/     // at least n number
/^[A-za-z]+$/ // matching only chars
              // Matching a username,length 3-16
              // Matching a password,length 8-18
              // Matching an Email Address
              // Validating Numeric Ranges 000..255
              // Matching an IP Address
              // validation for telephone XXXX-XXXXXXX XXX-XXXXXXX
              // Validating URL
/< (S*?)[^>]*>.*?|< .*? />/
              // find out all html tags

date2019-03-23 16:00:01 From:www.jquerypluginhub.com Author:JPH
Related Tags:

Leave a Reply

Your email address will not be published. Required fields are marked *