Reputation: 697
I want to avoid "000-000-0000" in my text box.
<div class="inner-addon right-addon">
<input id="PhoneHtmlId" type="text" class="form-control" maxlength="12" autocomplete="off" patternValidator=""
validation [controlRef]="form.controls.HomePhone" [requiredValidator]="true"
formControlName="Phone" name="PhoneHtmlId" [mask]="{ mask: '999-999-9999', placeholder: '___-___-____', clearIfNotMatch: false }" />
</div>
It is a masked text box. I need a patternValidator that is regex to avoid it. Can you please help me in writing regex for the same.
Upvotes: 0
Views: 128
Reputation: 697
Here is the solution :
/^(?!000-000-0000)[0-9-]{12}$/
it will accept everything except all zero.
Please refer the below plunger and replace the ng-pattern data with the above regex.
Upvotes: 0
Reputation: 1476
The following should do the job
^(?!000-000-0000)$
for you reference: http://www.regular-expressions.info/lookaround.html
EDIT: Based on the comment, you are looking for the following:
^[1-9]{3}-[1-9]{3}-[1-9]{4}$
Upvotes: 1