Regular expressions for numeric input

69 views Asked by At

I need a regular expression in which user could input only numeric or there be asterisk in the end. for example

12345, 123*, 5677*, *

but I don't know how to do this. any help?

I have tried this regular expression for numeric input but I don't know that if I want asterisk(*) in the end than what should be the regular expression

^[0-9]+$
1

There are 1 answers

2
Sabuj Hassan On BEST ANSWER

Since the input can be only * as well, so make the digit(0-9) portion optional and add additional \* at the end to accept asterisks.

^([0-9]+|[0-9]*\*)$