In Web Development, there have forms we need to secure and validate using Regular Expression, in some cases are registration form, transaction forms such as valid email, valid postal code, matching strong password and securities.
In this article, i have compiled the useful of JavaScript Regular Expression, this is the most common regular expression we use in web development such validating forms. These Regular Expression will not match in common cases, it even fewer special cases you might be need, because any Regular Expression can be written broadly and narrowly, meaning, broadly is a match a lot of pattern and narrowly is very restricted in matching.
1. Matching names
Regex:
String that matches:
Pattern can match any valid names with first character capitalize.
2. Matching postal codes
Regex:
String that matches:
Pattern can match postal codes broadly, they match mostly US postal code.
3. Matching email addresses
Regex:
String that matches:
Pattern can match any valid email format, however this is most common use for validating email in registration form.
4. Matching urls
Regex:
String that matches:
In the form, might have a extra field to input the user for URL, this regex validate the valid url.
5. Matching decimal numbers
Regex:
String that matches:
Pattern match a valid decimal numbers.
5. Matching currencies
Regex:
String that matches:
Pattern can match the right currencies, in reg ex you can add more currencies to match.
6. Matching ip addresses
Regex:
String that matches:
Pattern can match the right ip address, obviously the ip address ’999.999.999.999′ will not match.
7. Matching dates
Regex:
String that matches:
Pattern can matches the date format, year, month and day.
8. Matching time in 12hrs
Regex:
String that matches:
Pattern can match 12 hrs time. it match up to 12:59 am and pm.
9. Matching time in 24hrs with Time zone
Regex:
String that matches:
Pattern can match 24 hrs time. it match up to 23:59 including timezone.
10. Matching HTML tags
Regex:
String that matches:
Pattern can match HTML tags.
11. Validating strong passwords
Regex:
String that matches:
This pattern help to make sure user give a secure password that’s harder for hacker to crack it.
Pattern for password requires.
- Password Any character, except space.
- Password at least 8 characters long
- And not more than 15 characters.
- Password must have a number.
- Password must have a special character.
12. Matching credit card numbers
Regex:
String that matches:
Pattern can match 4 major of credit card numbers, American Express, Visa, MasterCard, Discover.
No comments:
Post a Comment