0

Hi everyone,
I am trying to validate a user registration form. User must enter letters and/or letters only.

//check username
	$_POST['user_name'] = trim($_POST['user_name']);
	$checkChar ='/^[a-zA-Z0-9]+$/';
	if (!preg_match($checkChar, ($_POST['user_name']))); {
		$error['char'] = 'Username must contain letters or numbers only';
	}

When I submit the error message keeps coming up when it should not.
Any thoughts?

2
Contributors
2
Replies
3
Views
7 Years
Discussion Span
Last Post by vitana
0

Sorry,
I had a semicolon at end of line ending statement.

0

Hi everyone,
I am trying to validate a user registration form. User must enter letters and/or letters only.

//check username
	$_POST['user_name'] = trim($_POST['user_name']);
	$checkChar ='/^[a-zA-Z0-9]+$/';
	if (!preg_match($checkChar, ($_POST['user_name']))); {
		$error['char'] = 'Username must contain letters or numbers only';
	}

When I submit the error message keeps coming up when it should not.
Any thoughts?

I use following php code to validate i18n user name ($value)

if (preg_match('/[~!@#$%^&\*\(\)\+={}\[\]|\\:;"<>\?\/]/', $value))
			return new ValidationError($field, $value, "$field has unavailable symbols: $value");
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.