Reputation: 8912
I have come up with the following regex
sample to allow everything from keybaord except float(decimal value) e.g. .1, 0.1, 1.1, 1.1., 1.1.1 etc
ng-pattern="/^[\w -!@#$%^&\*()\+]*$/" />
Is there a short way to write regex for my requirement i.e. Allow everything from keyboard except loat(decimal value) e.g. 0.1, 1.1, 1.1. etc?
Upvotes: 0
Views: 902
Reputation: 174696
Use a negative lookahead based regex.
^(?!\d*\.\d+$).*
(?!...)
called negative lookahead which asserts that the match won't be followed by the text which was matched by the pattern present inside the negative lookahead. So here, ^(?!\d+\.\d+$)
, it matches the start of the line boundary only if the start of the line boundary was not followed by a \d+\.\d+$
decimal number.
Upvotes: 1
Reputation: 67968
^[\w !@#$%^&\*()\+-]*$
^^ ^^
Your regular expression cannot accept decimals
as it cannot match .
.You need to place -
at the end
or escape
it/
Upvotes: 0