Reputation: 1438
Hi I am creating a regex to have:
02
or +612
02
to have 10 digits in total excluding space+612
to allow +
and 11 digits excluding space+612
, replace +61
with 0
Currently, I created
^(\+612)\d{8}$
Can anyone help me or suggest me how can I add the above validations in the regex.
Any help or suggestion would be appreciated.
Thanks in advance
Upvotes: 0
Views: 113
Reputation: 48711
You need to have an alternation that starts matching at two points and do the replacement afterwards:
^ *(?:0 *2|\+ *6 *1 *2)(?: *\d){8} *$
JS code:
if (/^ *(?:0 *2|\+ *6 *1 *2)(?: *\d){8} *$/.test(phoneNumber)) {
phoneNumber = phoneNumber.replace(/^ *\+ *6 *1/, 0);
}
Upvotes: 3