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?

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

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");
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.