alpha is a simple alpha / alphanumeric validator that allows you to customize it as you want to.
Yii 1.1.7
to use alpha inside your model simply store its file into your application extensions directory and then use the rule
/** * Declares the validation rules. */ public function rules() { return array( // name, email, subject and body are required array('email, subject, body', 'required'), array('name', 'ext.alpha'), // email has to be a valid email address array('email', 'email'), ); }
if you won't use any additional parameter alpha will validate any string with just basic alpha characters with a length of at least 1.
Here are the additional parameters you can use, and keep in mind that you can use all of them together:
ÀÁÂÃÄĀĂÈÉÊËĚĔĒÌÍÎÏĪĨĬÒÓÔÕÖŌÙÚÛÜŪŬŨàáâãäāăèéêëēěĕ
ìíîïīĩĭòóôõöōŏùúûüūŭũ
ÀÁÂÃÄÅĀĄĂÆÇĆČĈĊĎĐÈÉÊËĒĘĚĔĖĜĞĠĢĤĦÌÍÎÏĪĨĬĮİIJĴĶŁĽĹĻ
ĿÑŃŇŅŊÒÓÔÕÖØŌŐŎŒŔŘŖŚŠŞŜȘŤŢŦȚÙÚÛÜŪŮŰŬŨŲŴÝŶŸŹŽŻàá
âãäåāąăæçćčĉċďđèéêëēęěĕėƒĝğġģĥħìíîïīĩĭįıijĵķĸłľĺ
ļŀñńňņʼnŋòóôõöøōőŏœŕřŗśšşŝșťţŧțùúûüūůűŭũųŵýÿŷžżź
ÞþßſÐð
/** * Declares the validation rules. */ public function rules() { return array( // name, email, subject and body are required array('email, subject, body', 'required'), array('name', 'ext.alpha', 'extra' => array('-', '_')), // email has to be a valid email address array('email', 'email'), ); }
every character you'll use in extra will be escaped, so you shouldn't have to worry about anything.
Keep in mind that this validation rule is not doing any conversion of the string (no htmlspecialchars, no htmlentities). Be always careful about how to save strings containing accented letters into your database.
Total 4 comments
Hey nickcv, it's almost 3 months since FARAZFRANK's comment and the download is still not working. Please check! Thx
your ext file is corrupt, upload new once.
Just in case, make sure you use false without quotes, otherwise allowSpaces and other options may not work.
Here is what I mean: http://snippet.io/snippet/29-allowspaces-yii-not-working-with-false-between-quotes
I had a problem with the extra option
Because the first character was not escape. I solve this with change
with
Leave a comment
Please login to leave your comment.