how to validate the user input to remove any special chahracters

hi, can anyone tell me that how to remove special characters from the user input and to format the user such as:

123user, user-11, _user, $user etc,

i m using varchar in db for user name.

plus if i have like attribute gender and i want it to be unselected by default and want to use a dropdownlist to select gender from it how can i do it?

For validate the username this rule:

 array('username', 'match', 'pattern'=>"/^([a-z0-9_-]*)$/", 'message'=>'url invalid: only letters, number, "-" and "_"'),

For make a ddl for gender:

$form->dropdownList($model, 'gender', array('m'=>'Male', 'f'=>'Female', 'h'=>'Hybrid'), array('prompt'=>''));

The htmlOptions prompt will leave it unseleted by default.

1 Like

thanks this worked perfect

Glad it helped!

P.s: welcome to the forum!