0

Good day,

I'm trying to get the length of an value interred into a input field. The value entered needs to be 13 characters long, no less no more. And must be numerical numbers.

Here is my JS code:

value = '8312258066038';
re = new RegExp('^\d{13}$');
alert(re.match(value));

The answer is supposed to be true if the value is 13 characters.

1

1 Answer 1

2

Use test() not match()

value = '8312258066038';
re = /^\d{13}$/;
alert(re.test(value));
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.