Anirudh Agarwal
Anirudh Agarwal

Reputation: 697

Regex to avoid all zero in the masked text box

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

Answers (2)

Anirudh Agarwal
Anirudh Agarwal

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.

Plunger for the demo

Upvotes: 0

mehran
mehran

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

Related Questions