0 votes
1 view
in Salesforce by (11.9k points)

I need a regex to limit number digits to 10 even if there are spaces.

For example it allows 06 15 20 47 23 the same as 0615204723.

I tried: ^\d{10}$, but how do I ignore spaces?

Also, the number should start with 06 or 07. (Editor's note, the last requirement was from comments by the OP.)

1 Answer

0 votes
by (30.1k points)

Here is what you can do as this will do it in most regex systems.


But assuming you really only want the number, then go ahead and break it into 2 steps.

For example, in JavaScript:

var s = ' 06 15 20 47   34 ';

s = s.replace (/\s/g, "");

isValid = /^0[67]\d{8}$/.test (s);

Related questions

Welcome to Intellipaat Community. Get your technical queries answered by top developers !