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?

Link to comment
Share on other sites

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_.@-]+$");
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.