validation - Validate PHP form field if not left empty -


i have bit of problem php form validation use with.

i got optional field should validated if user fills it, otherwise form should processed normal. here's validation field:

if (!preg_match("/(0?\d|1[0-2]):(0\d|[0-5]\d) (am|pm)/i", '$start')) :         $errors->add('submit_error', __('<strong>error</strong>: time incorrect', 'appthemes'));         endif; 

might simple, @ moment can't head around how can bypass validation if field left empty. ideas?

if(!empty($your_field) && !preg_match(...)) 

php tests if field null before testing regex. if field null php jump next instruction.


Comments

Popular posts from this blog

c# - SharpSVN - How to get the previous revision? -

c++ - Is it possible to compile a VST on linux? -

url - Querystring manipulation of email Address in PHP -