Reputation: 1675
I want to allow only a-z, 0-9,
and . - _
character using onkeyup
in input box:
I use this code:
<input type="text" onkeyup="this.value=this.value.replace(/[^a-z0-9]/gi, '');" required>
But now I can't write this . - _
character
How to allow this? But restrict only special character like @
#
My value is:
sabbir@
--> only remove @
character,
sabbir_ahmed
--> its allow
sabbir.ahmed
--> its allow
So I want to remove only special characters like @
, #
, $
etc.
Upvotes: 1
Views: 1140
Reputation: 147146
You just need to add the characters you want to allow to your character class:
<input type="text" onkeyup="this.value=this.value.replace(/[^a-z0-9 ._-]/gi, '');" required>
Upvotes: 1