Skip to content

Commit b52564c

Browse files
authored
Make regex testing better and faster
1 parent 4e3c7de commit b52564c

File tree

1 file changed

+5
-11
lines changed

1 file changed

+5
-11
lines changed

regex/index.js

+5-11
Original file line numberDiff line numberDiff line change
@@ -2,30 +2,24 @@ class Regex {
22
/**
33
* this package is checking that user input value is persian or not .
44
*/
5-
isPersian(String) {
6-
const regex = /^[\u0600-\u06FF\s]+$/;
7-
const regexRul = new RegExp(regex);
8-
return String.match(regexRul) !== null;
5+
isPersian(string) {
6+
return /^[\u0600-\u06FF\s]+$/.test(string);
97
}
108

119
/**
1210
* this function is validating numbers
1311
*/
1412
isNumber(number) {
15-
const regex = /^[+-]?\d+(\.\d+)?$/;
16-
const regexRul = new RegExp(regex);
17-
return regexRul.test(number)
13+
return /^[+-]?\d+(\.\d+)?$/.test(number)
1814
}
1915

2016
/**
2117
* this function is validating emails
2218
*/
2319

2420
isEmail(email) {
25-
const regex = /^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
26-
const regexRul = new RegExp(regex);
27-
return !!email.match(regexRul);
21+
return /^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/.test(email);
2822
}
2923
}
3024

31-
module.exports = new Regex();
25+
module.exports = new Regex();

0 commit comments

Comments
 (0)