ksa
Posts: 27
|
Posted: 04/03/2011, 3:46 AM |
|
I've been searching this forum and the web in general for a solution to this without coming up with anything that works. I have a feature where users can register a username and password. I need to prevent people from including spaces and special characters when they submit the registration form.
I realize I need to fill in something in the "Validation Rule" field for that form field - which is simply called "username" - but nothing I have tried seems to be working. All I get is an error message when try to load the page. What exactly should it say? If someone could spell it out for me, I would truly appreciate it. I know very little coding lingo.
|
|
|
Waspman
Posts: 948
|
Posted: 04/04/2011, 1:08 AM |
|
I just put something like this in the onvalidate event:
if ( preg_match('!^[^a-zA-Z0-9]+$!', $Component->pw->Value) == 1 ) {
$Component->Errors->addError("Password contains invalid characters");
}
I also add:
if ($Component->password_check->Value != $Component->pw->Value) {
$Component->Errors->addError("The Password and the Password confirmation don't match");
} elseif (strlen($Component->pw->Value) < 7) {
$Component->Errors->addError("Password to short");
}
_________________
http://www.waspmedia.co.uk |
|
|
ksa
Posts: 27
|
Posted: 04/05/2011, 9:14 AM |
|
Thanks for your help. Unfortunately, no matter where I enter the code or how I tweak it, it makes no difference. It keeps accepting all characters. I assume the "pw" part in my case should be replaced with "username" since that's the field in question, so that's what I've been doing.
The other part - the two matching passwords - I already got to work, so that's not a problem.
|
|
|
Waspman
Posts: 948
|
Posted: 04/06/2011, 2:07 AM |
|
Sorry try this in the input validation of the text box: ^[a-zA-Z0-9_]{1,}$
It works for me:)
_________________
http://www.waspmedia.co.uk |
|
|
ksa
Posts: 27
|
Posted: 04/06/2011, 10:48 AM |
|
Thank you! That did the trick! But not until I had deleted the PHP file and regenerated it. I appreciate your help.
|
|
|