Tuesday, April 26, 2011

Validating the constant name (Recurcivly)

It will recursively check that given text is valid constant name or not.

Pattern Rules:
1. Only A to Z , underscore (_) are allowed.

2. Repeating underscores (_) at once are now allowed.

3. Up to 45 chars allowed.

<?php  


/*
    Validating the constant name (Recurcivly)
    -----------------------------------------
    (Logic/Pattern) Written by Junaid Atari

    + Examples:
      - ACCESS_IS_ALLOWED
      - DIR_SEPERATOR
      - HOLDER
      - N_A_M_E_I_S_N_O_N_E
*/

//# Constant name to validate.

$name 'ACTION_STATUS';

echo 
preg_match ('/^([A-Z]{1}([_]?)){2,43}[A-Z]$/'$name)
        ? 
'Constant name is Valid'
        
'
Constant name is not valid';

0 comments:

Post a Comment