ziaulain
ziaulain

Reputation: 94

Regex matching specific pattern with numbers. Allowed number 0 and greator than 5

i want to allow 0 and greator than 5 numbers in an input field.

Allowed Numbers: 0, 5, 10, 11, 12 ...

Not Allowed Numbers negative number, 1,2 3, 4

 <span matPrefix>$ </span>
 <input id="hourlyrate" type="number" pattern="^[+]?([0-9]+(?:[\.][0-9]*)?|\.[0-9]+)$"min="5"name="hourlyrate"#hourlyrate="ngModel"matInput[disabled]="!editRate"[(ngModel)]="skill.price"required>
 <span matSuffix>per 15 minutes</span>
 <mat-error *ngIf="hourlyrate.invalid">
   <span *ngIf="hourlyrate.errors?.required">This field is required.</span>
   <span *ngIf="hourlyrate.errors?.pattern">Minimum price should be $5.</span>
   <span *ngIf="hourlyrate.errors?.min">Minimum price should be $5.</span>
 </mat-error>

Upvotes: 0

Views: 48

Answers (1)

Toto
Toto

Reputation: 91430

I'd use:

^(?![1234]$)\d+$

Explanation:

^               # beginning of string
    (?!         # negative lookahead, make sure we haven't after:
        [1234]  # one of the digit 1 or 2 or 3 or 4
        $       # end of string
    )           # end lookahead
    \d+         # 1 or more digits
$               # end of string

Upvotes: 1

Related Questions