Explore Courses Blog Tutorials Interview Questions
0 votes
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 (32.1k points)
edited by

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);

Enroll in our Salesforce training to become as an Expert in Salesforce!

Related questions

0 votes
1 answer
0 votes
1 answer
asked Nov 12, 2020 in Python by ashely (50.2k points)
0 votes
1 answer
+1 vote
1 answer

Browse Categories