Validation question |
[eluser]magicPants[/eluser]
I'm just getting into using CI and I'm really loving it. I have a question re: validation and was wondering if someone could help please? How would I set up a validation rule based on a regular expression e.g. validating phone number (containing numbers and spaces only), or validating an ISBN? TIA Dave (magicPants)
[eluser]champs[/eluser]
Look a bit further into the validation class docs and check out the section on callbacks. Validation supports any available function that can be called with a single argument.
[eluser]magicPants[/eluser]
Nice! Thank you. But what if I have a validation function that I need to call for different controllers, I don't want to be cutting & pasting the same validation function? Is there a place I can put this where all controllers can get at it, or would I need to add it to the validation library? Cheers Dave
[eluser]mk3[/eluser]
I believe u can extend validation library... not only rewrite... I believe that extending validation class is better practice then adding your own code to it. Think how painful will be future uppdates EDIT: Yes I can confirm u can extend validation class... how to do it it is written in user manual
[eluser]magicPants[/eluser]
OK. I think I've found it. Creating libraries: http://ellislab.com/codeigniter/user-gui...aries.html, with this I should be able to extend the core validation library and add in my own functions. Thank you. This framework is a breath of fresh air compared to the .NET bloat I've been using recently. Cheers Dave |
Welcome Guest, Not a member yet? Register Sign In |