CodeIgniter Form Validation Rules

Rule Reference

The following is a list of all the native rules that are available to use:

RuleParameterDescriptionExample
requiredNoReturns FALSE if the form element is empty.
matchesYesReturns FALSE if the form element does not match the one in the parameter.matches[form_item]
regex_matchYesReturns FALSE if the form element does not match the regular expression.regex_match[/regex/]
differsYesReturns FALSE if the form element does not differ from the one in the parameter.differs[form_item]
is_uniqueYesReturns FALSE if the form element is not unique to the table and field name in the parameter. Note: This rule requires Query Builder to be enabled in order to work.is_unique[table.field]
min_lengthYesReturns FALSE if the form element is shorter than the parameter value.min_length[3]
max_lengthYesReturns FALSE if the form element is longer than the parameter value.max_length[12]
exact_lengthYesReturns FALSE if the form element is not exactly the parameter value.exact_length[8]
greater_thanYesReturns FALSE if the form element is less than or equal to the parameter value or not numeric.greater_than[8]
greater_than_equal_toYesReturns FALSE if the form element is less than the parameter value, or not numeric.greater_than_equal_to[8]
less_thanYesReturns FALSE if the form element is greater than or equal to the parameter value or not numeric.less_than[8]
less_than_equal_toYesReturns FALSE if the form element is greater than the parameter value, or not numeric.less_than_equal_to[8]
in_listYesReturns FALSE if the form element is not within a predetermined list.in_list[red,blue,green]
alphaNoReturns FALSE if the form element contains anything other than alphabetical characters.
alpha_numericNoReturns FALSE if the form element contains anything other than alpha-numeric characters.
alpha_numeric_spacesNoReturns FALSE if the form element contains anything other than alpha-numeric characters or spaces. Should be used after trim to avoid spaces at the beginning or end.
alpha_dashNoReturns FALSE if the form element contains anything other than alpha-numeric characters, underscores or dashes.
numericNoReturns FALSE if the form element contains anything other than numeric characters.
integerNoReturns FALSE if the form element contains anything other than an integer.
decimalNoReturns FALSE if the form element contains anything other than a decimal number.
is_naturalNoReturns FALSE if the form element contains anything other than a natural number: 0, 1, 2, 3, etc.
is_natural_no_zeroNoReturns FALSE if the form element contains anything other than a natural number, but not zero: 1, 2, 3, etc.
valid_urlNoReturns FALSE if the form element does not contain a valid URL.
valid_emailNoReturns FALSE if the form element does not contain a valid email address.
valid_emailsNoReturns FALSE if any value provided in a comma separated list is not a valid email.
valid_ipYesReturns FALSE if the supplied IP address is not valid. Accepts an optional parameter of ‘ipv4’ or ‘ipv6’ to specify an IP format.
valid_base64NoReturns FALSE if the supplied string contains anything other than valid Base64 characters.

Note

Leave a Reply

Your email address will not be published. Required fields are marked *