Welcome Guest, Not a member yet? Register   Sign In
[Solved] Regex Check Codeigniter Form Validation
#7

(11-06-2015, 02:34 PM)mwhitney Wrote:
(11-06-2015, 01:46 PM)wolfgang1983 Wrote: Update:
I have tried this now. Just would like to know if correct?

PHP Code:
<?php

class MY_Form_validation extends CI_Form_validation {

 
  function has_capital($str) {
    if (
$this->regex($str) == FALSE) {
 
          $this->set_message('has_capital''Your ' .$str' needs to have at least one upper case letter');
     
  return false;
    } else {
     
  return true;
    }
 
   
    
 
   function regex($str) {
 
       $found FALSE;

 
       for ($i 0$i strlen($str); $i++) {
 
           if (ord($str[$i]) >= 65 && ord($str[$i]) <= 90) {
 
               $found true;
 
               break;
 
           }
 
       }

 
       return $found;
 
   


The set_message() call should probably be:
PHP Code:
$this->set_message('has_capital''Your {field} needs to have at least one upper case letter'); 


If you want to display what they input, you can use {param} in your message text. See http://www.codeigniter.com/user_guide/li...r-messages

Thanks for that tip
There's only one rule - please don't tell anyone to go and read the manual.  Sometimes the manual just SUCKS!
Reply


Messages In This Thread
RE: Regex Check Codeigniter Form Validation - by wolfgang1983 - 11-06-2015, 02:50 PM



Theme © iAndrew 2016 - Forum software by © MyBB