Regex for number with or without extension

163 Views Asked by At

How can I validate a number with or without the '+' extension using regex?.

I am using reactive forms Angular 2 and as I have it at the moment the validation is done when the '+' is included only. When I omit the '+' extension the validation fails

['', [Validators.required, Validators.pattern('[+]{1}[0-9]+')]],
1

There are 1 best solutions below

0
On BEST ANSWER

if you want [+] to be optional you can use

[+]{0,1}[0-9]+   

or

[+]?[0-9]+