0

I have tried this code but it is not working.

<div>
    <span *ngIf="!usernameRef.errors?.required">Amount</span>
    <span *ngIf="!usernameRef.errors?.required">Cover amount required.</span>
    <span *ngIf="usernameRef.errors?.pattern">Cover amount invalid.</span>

     <input type="number" name="Amount" class="form-control" data-field="validate" placeholder="50 000" [(ngModel)]="Amount" 
    required #usernameRef="ngModel" pattern="[0-9]*" /> 
    </div>
1
  • have you fields are wrapped inside form? Commented Dec 21, 2016 at 14:11

1 Answer 1

1

Your regex is also valid from two reasons:

  1. Your input type is a number. You can't type letters.
  2. [0-9]* - the asterisk means - 0 or more occurrences.
Sign up to request clarification or add additional context in comments.

1 Comment

1. Input type is number. It will not take any special character only taking + and - . I want to restrict + and - also.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.