1

i want a javascript regex for my input that accept only numbers with 10 or 12 digits. forexample:

1234567890 => True

a12345678u =>False

123456789123 =>True

sj231@ => False

aq123456789t =>False

i very very appreciate if any one can help me.

0

1 Answer 1

3

Try: [0-9]{10}([0-9]{2})?

const regex = new RegExp("[0-9]{10}([0-9]{2})?");

console.log(regex.test('1234567890'));
console.log(regex.test('a12345678u'));
console.log(regex.test('123456789123'));
console.log(regex.test('sj231@'));
console.log(regex.test('aq123456789t'));

regex101 explanation:

enter image description here

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.