![]() |
Form Validation alpha numeric dash "space" - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived General Discussion (https://forum.codeigniter.com/forumdisplay.php?fid=21) +--- Thread: Form Validation alpha numeric dash "space" (/showthread.php?tid=31517) |
Form Validation alpha numeric dash "space" - El Forum - 06-22-2010 [eluser]wdcmatt[/eluser] alpha numeric dash and SPACE! I searched google for about 20 min and did not find a nice way to do this, i found a few poorly written one line scripts, still not to my liking, here is what I came up with hopefully it can help someone else... Code: /** And then I use this as a callback Code: $this->load->library('validation'); Notice the double underscore after callback.... Well in any case I hope this helps someone. Form Validation alpha numeric dash "space" - El Forum - 07-21-2010 [eluser]Watnow[/eluser] You can better extend you're form validation class en use this one: Code: function alpha_dash_space($str) Code: $lang['alpha_dash_space'] = "The %s field may only contain alpha-numeric characters, underscores, and dashes/spaces."; I'v test it and its works.. and then you dont have to use it a callback function, just normal. Form Validation alpha numeric dash "space" - El Forum - 08-30-2010 [eluser]tomodatchi[/eluser] just use jquery function like below in your views/page : Code: jQuery(function() { Form Validation alpha numeric dash "space" - El Forum - 08-30-2010 [eluser]WanWizard[/eluser] Never rely on client-side validation! It can be easily worked around. Always validate server-side! Form Validation alpha numeric dash "space" - El Forum - 08-30-2010 [eluser]tomodatchi[/eluser] Better use both (client & server side validation) The Cons of using one or the other : With client side validation only, if a user disables JavaScript, then no validation will occur. With server side validation only, there are more return trips to the server which in turns uses more resources and slows down the site when a client side script could have done the validation without the server. The Pros of having both : The data will always be validated, whether or not the client has JavaScript enabled or not. There will be less server strain with the client side validation. The client can fix form errors faster with instant client side notifications. The data will have a bit more integrity going through the dual validation process. Form Validation alpha numeric dash "space" - El Forum - 07-17-2012 [eluser]Diggory Laycock[/eluser] Thanks for this post - very useful. I'd just like to point out something which caught me out: If extending the form_validation class then you need to do a little more than is in the docs: Code: <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); Note the $rules argument in the constructor. Form Validation alpha numeric dash "space" - El Forum - 09-02-2012 [eluser]TunaMaxx[/eluser] [quote author="Diggory Laycock" date="1342528937"]If extending the form_validation class then you need to do a little more than is in the docs... Note the $rules argument in the constructor.[/quote] Do you have more information on this? I've never run in to the issue and I'd love to know what I am missing by not supplying the $rules argument. Form Validation alpha numeric dash "space" - El Forum - 09-02-2012 [eluser]Aken[/eluser] The Loader class passes any config rules from config files through that param of the construct function. See /core/Loader.php :: _ci_load_class() and _ci_init_class(). Form Validation alpha numeric dash "space" - El Forum - 09-04-2012 [eluser]TunaMaxx[/eluser] Thank you. I did not know that! |