Australian Mobile number regular expression valida

2019-07-17 02:23发布

问题:

I need to validate the mobile number

  • first text input starting with 04
  • should be total 10 digits including 04(eg : 0412345678)

my input field is below

<form name="uploadForm">
<input type="tel" name="MobileNumber" id="MobileNumber" data-ng-model="ApplicationData.MobileNumber" required maxlength="14" data-ng-pattern="/^(0?4[0-9]{8}/\s)$/">
<span data-ng-show="uploadForm.MobileNumber.$error.pattern">Please enter a valid mobile number.</span>

<input type="tel" name="Number" id="Number" data-ng-model="ApplicationData.Number" required maxlength="14" data-ng-pattern="/(^1300\d{6}$)|(^1800\d{6}$)|(^0[2|3|7|8]{1}[0-9]{8}$)|(^04\d{2,3}\d{6}$)/">

<span data-ng-show="uploadForm.Number.$error.pattern">Please enter a valid mobile number.</span>

</form>

any one can you help me please ?

回答1:

I think for your first question replace with this regexp. it accepts space in between number.

ng-pattern="/^04(\s?[0-9]{2}\s?)([0-9]{3}\s?[0-9]{3}|[0-9]{2}\s?[0-9]{2}\s?[0-9]{2})$/"

for your second question, its quite long this is what i can come up with at this moment.

ng-pattern="/(^1300\s?([0-9]{3}\s?[0-9]{3}|[0-9]{2}\s?[0-9]{2}\s?[0-9]{2})$)|(^1800\s?([0-9]{3}\s?[0-9]{3}|[0-9]{2}\s?[0-9]{2}\s?[0-9]{2})$)|(^0[2|3|7|8]{1}[0-9]{8}$)|(^04(\s?[0-9]{2}\s?)([0-9]{3}\s?[0-9]{3}|[0-9]{2}\s?[0-9]{2}\s?[0-9]{2})$)/"

any body have interest to modify/short this one.



回答2:

If I understand this correctly, this is your regex pattern.

^04[0-9]{8}$

^04 - starts with 04
[0-9]{8} - matches the next 8 digits
$ - matches end of string