Prevent the use of symbols - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23) +--- Thread: Prevent the use of symbols (/showthread.php?tid=36190) |
Prevent the use of symbols - El Forum - 11-24-2010 [eluser]flyenig[/eluser] I have 2 inputs where people can type their firstname or lastname. I dont want them to type any symbol with their name (eg, @, *,$,%,!,♥...hearts. backwards letters, etc.) and I dont want them to have any punctuation marks with their name either. (Kenny. Kenny, Kenny!) none of that. How can i prevent this from happening? thanks Prevent the use of symbols - El Forum - 11-24-2010 [eluser]vitoco[/eluser] - on the client side you can use maskedinput plugin for jquery. - on server side you can clean the input using a regular expresion Saludos Prevent the use of symbols - El Forum - 11-24-2010 [eluser]skunkbad[/eluser] I think you might like this script that I wrote for client side limiting of chars. You can use it a few ways. I am usually using it with regex: Code: <!DOCTYPE html> Prevent the use of symbols - El Forum - 11-24-2010 [eluser]skunkbad[/eluser] The script tags were replaced with [removed], so just change them... and the script in the head was a link to jquery. Prevent the use of symbols - El Forum - 11-25-2010 [eluser]nuwanda[/eluser] The simple solution, and the one you should use, is the form validation rule in CI. http://ellislab.com/codeigniter/user-guide/libraries/form_validation.html The alpha rule. Prevent the use of symbols - El Forum - 11-25-2010 [eluser]skunkbad[/eluser] [quote author="nuwanda" date="1290697437"]The simple solution, and the one you should use, is the form validation rule in CI. http://ellislab.com/codeigniter/user-guide/libraries/form_validation.html The alpha rule.[/quote] Of course you should provide form validation, but when a developer becomes lazy and does not provide client side validation of form fields, then the site visitors are inconvenienced with potentially re-submitting a form until they figure out the expected input. Prevent the use of symbols - El Forum - 11-25-2010 [eluser]nuwanda[/eluser] It's not about being lazy. It's really a matter of UI design philosophy. If your inputs have good instructions in the first place (see stackoverflow's system), and your validation messages are good, most users wouldn't need to submit a form more than twice to get it done. That said, I think client-side validation can be helpful if you don't a) overuse it, and b) rely upon it. Anyway, here's a little jQuery I use to reject characters in inputs: Code: $('#input').keyup(function(){ That takes the current value of the input, and replaces the regex of unwanted characters with an empty string. To the user it looks like their input didn't happen. In the above, anything that is not lowercase alphanumeric, a space, or a dash is rejected. Prevent the use of symbols - El Forum - 12-06-2010 [eluser]flyenig[/eluser] sorry guys i was on a little vacation, thanks for replying, ill try out the soulutions Prevent the use of symbols - El Forum - 12-07-2010 [eluser]skunkbad[/eluser] [quote author="flyenig" date="1291721260"]sorry guys i was on a little vacation, thanks for replying, ill try out the soulutions[/quote] You might consider that my solution covers the pasting of data into the input. Of course, you should do your own testing. |