Custom validation rules? |
[eluser]RyanH[/eluser]
I'd like to create some custom validation rules, but I'm not sure how. The most important rule I want to create is to specify the email address. I want someone's email address to match only certain domains. For example, I only want email addresses that are coming from Gmail. [email protected] would work, but email@yahoo.com would not. Any advice? Thanks.
[eluser]Pascal Kriete[/eluser]
Something like this might work: Code: $parts = explode("@", $email);
[eluser]xwero[/eluser]
Code: class MY_Validation extends CI_Validation Code: $rules['email'] = 'valid_email|domain_email[gmail.com]';
[eluser]mironcho[/eluser]
Hi RyanH, If you don't prefer creating new class, you might create callback function in your controller - simply put xwero's domain_email function in your controller and use it in your rules in this manner: Code: $rules['email'] = 'valid_email|callback_domain_email[gmail.com]';
[eluser]RyanH[/eluser]
[quote author="mironcho" date="1200805002"]Hi RyanH, If you don't prefer creating new class, you might create callback function in your controller - simply put xwero's domain_email function in your controller and use it in your rules in this manner: Code: $rules['email'] = 'valid_email|callback_domain_email[gmail.com]'; Also, how do I go about creating a validation rule that allows spaces? I want to allow only alpha numeric, or just numeric, but also contain spaces. For example, a state name may have two words such as New York, but when you use the alpha or alpha_numeric rule, that returns false. |
Welcome Guest, Not a member yet? Register Sign In |