javascript - Australian Mobile number regular expression validation needs to allow space in between number - Stack Overflow

I need to validate the mobile number first text input starting with 04should be total 10 digits includ

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 ?

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 ?

Share Improve this question edited Aug 6, 2016 at 7:26 sheravanan asked Aug 6, 2016 at 7:19 sheravanansheravanan 911 gold badge1 silver badge6 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 6

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

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 e 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.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1743677727a4488853.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信