Bhinal Chauhan Bhinal Chauhan - 3 years ago 118
PHP Question

allow alphanum space alongwith dot special character in validation

->add('proposer_name', 'custom', [
'rule' => array('custom', '/^[a-z0-9 ]*$/i'),
'message' => __('Only alphanumeric characters are allowed')
])


This is the method I am using in server side validation for name. Also I want to write eg. Mr. ABC DEF in name field. But it is not allowing . in field. How should be my regex please help. I working in cakephp 3.x.

Answer Source

Just add the dot inside your character class (square brackets []). It has no special meaning inside.

 ->add('proposer_name', 'custom', [
                    'rule' => array('custom', '/^[a-z0-9 .]*$/i'),
                    'message' => __('Only alphanumeric characters are allowed')
                ])
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download