sufian Posted July 27, 2009 Share Posted July 27, 2009 hey I need a script for no dots so when some one fills in the input filed they are not able to put in dots. I have found one that removes spaces but not one that removes dots. remove spaces: <script type="text/javascript"> function nospaces(t){ if(t.value.match(/\s/g)){ alert('Sorry, you are not allowed to enter any spaces'); t.value=t.value.replace(/\s/g,''); } } </script> <input class="input mediumfield" name="username" onkeyup="nospaces(this)" type="text" value="" /> Quote Link to comment Share on other sites More sharing options...
Psycho Posted July 28, 2009 Share Posted July 28, 2009 Well, no matter what you do you also need to validate on the server page that processes the input. You can handle this in different ways. Personally I don't like scripts that validate on every keystroke. Instead I will validate onblur or on submission of the form. But, to each his own. The following function should work fine. <html> <head> <script language="JavaScript" type="text/javascript"> function hasPeriods(value) { return value.match(/\./); } function checkDot(fieldObj) { if (hasPeriods(fieldObj.value)) { alert('Periods are not allowed.'); fieldObj.value = fieldObj.value.replace('.', ''); } return; } </script> </head> <body> <input type="text" name="test_field" onkeyup="checkDot(this);" /> </body> </html> Quote Link to comment 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.