Jump to content

Prevent characters being typed


slj90

Recommended Posts

I use the following code to make it so users can only type a-z0-9 in the username text field. However, how would I add -_.@ to this for the email field?

var regex = new RegExp("^[a-zA-Z0-9]+$");

Thanks

Would it not be easier to use html and include the readonly attribute?

So your question is not about preventing people from typing, nor about how to prevent people from typing certain characters, but about how to add a couple more to the set of allowed characters?

 

Hyphen has a special meaning in character sets that goes away when you put it at the beginning or end (or a third way). The other three don't.

var regex = new RegExp("^[a-zA-Z0-9_.@-]+$");

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.