Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
144
rated 0 times [  146] [ 2]  / answers: 1 / hits: 17816  / 9 Years ago, thu, october 22, 2015, 12:00:00

How can I check the length of in String in JavaScript? Here is a small code example:



if(value != null && value !=  && value.length !== 10 && !value.match(/^d*$/)){

// do something

}


The expression 'value.length !== 10' doesn´t work. A String must contain at least 10 characters. How can I solve this problem?


More From » javascript

 Answers
97

Instead of match, test can be used with proper regex d{10,}.



if (value && /^d{10,}$/.test(value.trim()))

[#64643] Tuesday, October 20, 2015, 9 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
jaelyn

Total Points: 619
Total Questions: 102
Total Answers: 104

Location: Honduras
Member since Sun, Dec 26, 2021
2 Years ago
;