slj90 Posted February 15, 2015 Share Posted February 15, 2015 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 Quote Link to comment https://forums.phpfreaks.com/topic/294622-prevent-characters-being-typed/ Share on other sites More sharing options...
Tom10 Posted February 16, 2015 Share Posted February 16, 2015 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? Quote Link to comment https://forums.phpfreaks.com/topic/294622-prevent-characters-being-typed/#findComment-1505804 Share on other sites More sharing options...
requinix Posted February 16, 2015 Share Posted February 16, 2015 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_.@-]+$"); Quote Link to comment https://forums.phpfreaks.com/topic/294622-prevent-characters-being-typed/#findComment-1505840 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.