Regular expression examples in JavaScript

Today we will provide you a list of regular expression examples in JavaScript. While you are working with the real project then you might need to implement certain validation so these examples are helpful to you over there.

Regular expression examples in JavaScript, regex syntax, regular expression pattern matching example, regular expression for email, numbers only, mobile number, form validation, name and password, URL, CVV, Expiry Date.

Syntax: Validate the value by regular expression

Let’s take an example for different types of validations using regular expressions. It’s also possible to use different regex for the same validation.

Regular expression with examples

  1. Email validation
  2. Number validation
  3. Number validation for 10 digit
  4. Allow symbols in number validation
  5. URL validation
  6. Card CVV validation
  7. Card expiry date validation
  8. Percentage validation
  9. Password validation

1. Email validation

Regular expression for email validation.

2. Number validation

Use below regular expression to validate the number value.

3. Number validation for 10 digit

Regular expression to validate the 10 digit number.

4. Allow symbols in number validation

Regular expression to allow the few symbols like -,+,(,) including space in number validation between 10 to 14 digits.

5. URL validation

In order to validate the URL, use the regular expression below.

6. Card CVV validation

Use below regular expression to validate the card CVV number.

7. Card expiry date validation

To validate the card expiry date, use the regular expression below. Here we will consider the value in mm/YY format.

8. Percentage validation

Use below regular expression to validate the percentage value.

Here we allowed the 4 digits after the decimal point.

9. Password validation

Check below regular expression to validate the password in certain criteria. Like password must contain at least 8 characters, including uppercase, lowercase and numbers.

That’s it for today.
Thank you for reading. Happy Coding!

You may also like...

Leave a Reply

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