Regular Expression Exercises
RegEx Documentation
1. Write a JavaScript program to test the first character of a string is uppercase or not.
2. Write a JavaScript program to check a credit card number.
3. Write a pattern that matches e-mail addresses.
The personal information part contains the following ASCII characters.
Uppercase (A-Z) and lowercase (a-z) English letters.
Digits (0-9).
Characters ! # $ % & ' * + - / = ? ^ _ ` { | } ~
Character . ( period, dot or fullstop) provided that it is not the first or last character and it will not come one after the other.
4. Write a JavaScript program to search a date within a string.
5. Write a JavaScript program that work as a trim function (string) using regular expression.
6. Write a JavaScript program to count number of words in string.
Note :
- Remove white-space from start and end position.
- Convert 2 or more spaces to 1.
- Exclude newline with a start spacing.
7. Write a JavaScript function to check whether a given value is IP value or not.
8. Write a JavaScript function to count the number of vowels in a given string.
Test Data :
console.log(alphabetize_string('United States'));
Output :
"SUadeeinsttt"
9. Write a JavaScript function to check whether a given value is an valid url or not.
10. Write a JavaScript function to check whether a given value is alpha numeric or not.
11. Write a JavaScript function to check whether a given value is time string or not.
12. Write a JavaScript function to check whether a given value is US zip code or not.
13. Write a JavaScript function to check whether a given value is UK Post Code or not.
14. Write a JavaScript function to check whether a given value is Canada Post Code or not.
15. Write a JavaScript function to check whether a given value is a social security number or not.
16. Write a JavaScript function to check whether a given value is hexadecimal value or not.
17. Write a JavaScript function to check whether a given value is hexcolor value or not.
18. Write a JavaScript function to check whether a given value represents a domain or not.
19. Write a JavaScript function to check whether a given value is html or not.
20. Write a JavaScript function to check a given value contains alpha, dash and underscore.
21. Write a JavaScript function to print an integer with commas as thousands separators.
Test Data :
console.log(thousands_separators(1000));
"1,000"
console.log(thousands_separators(10000.23));
"10,000.23"
console.log(thousands_separators(100000));
"100,000"
Index