string validation regular expression validator minimum maximum length compare fields field match

string validation

Codepage-aware string validation helps validating string length, equality, difference, and regular expression patterns. 

Proper string validation means that we also care about the codepage - just think of multibyte characters in UTF-8, checking length or provide a safe regexp needs attention! For this reason you must set the way Clonefish handles codepages using form properties.

Depending on the codepage-related settings your regular expressions may be handled by preg_match, ereg or eregi on the PHP side. Use the PHP/JS regexp settings to define similar regular expressions in JS and PHP even if the regexp syntaxes are different.


<?php

$config 
= Array(

  
'element' => Array(

    
'type' => '...',
    
// ...further element settings here...

    
'validation' => Array( 

      Array(
        
'type'         => 'string',
        
'required'     => 1// required or not
        
'minimum'      => '2'// minimum length
        
'maximum'      => '5'// maximum length

        
'regexp'       => '/^[a-zA-Z]{5,10}$/'// regular expression to match
        
'regexpnot'    => '/^[a-zA-Z]{5,10}$/'// regular expression to unmatch
 
        // in several cases the same regexp cannot be used both in JS and PHP,
        // so we have separate settings for each.
        
'jsregexp'     => '/^[a-zA-Z]{5,10}$/'// JS regular expression to match
        
'jsregexpnot'  => '/^[a-zA-Z]{5,10}$/'// JS regular expression to unmatch
        
'phpregexp'    => '/^[a-zA-Z]{5,10}$/msUi'// PHP regular expression to match
        
'phpregexpnot' => '/^[a-zA-Z]{5,10}$/'// PHP regular expression to unmatch 

        
'equals'       => 'password2'// equals to another field (eg. two passwords)
        
'differs'      => 'fieldname'// differs from another field
        
'help'         => 'Help message value for this validator only'
      
)

    )
  )
);

?>


Live examples:

form validation for developers!

clonefish is a proven, mature form generator class that helps PHP developers to create, validate and process secure, flexible and easy-to-maintain forms
learn more
Bookmark and Share