Jump to content

Control Form Input?


justlukeyou

Recommended Posts

I have a number of Forms which I want to control the input, for example prevent people from using numbers or ensure that people use specific characters.

 

For example "Your password must contain a capital letter and at least one number".

 

Does anyone know what code I should use to do this. 

Link to comment
Share on other sites

you might want to and the start ^ and end $ of the string.

 

if (preg_match("/^[a-zA-Z0-9]+$/", $membername) == 0 && !$error) {

 

that way it will only pass this test if the whole string consists of nothing but those characters.

 

for the length thing, strlen() can tell you the length of the string.

Link to comment
Share on other sites

Brilliant thanks,  I have this but I want spit out as error which I am currently doing with lots of other errors.  I have $error set in a table which controls the font so it would be handy if I could continue to use it..

 

if (strlen($membername) > 15) && !$error) {    
$error = "The username must not exceed 15 characters.";
    }

 

I have this working:

 

if((!isset($password2) || empty($password2)) && !$error) {
        $error = "You need to enter your password twice.";
    }

Link to comment
Share on other sites

that looks fine, although there is no need to check !$error all the time... you can just do

 

if (strlen($membername) > 15){
    $error = 'The username must not exceed 15 characters.';
}else if (empty($password2)){
    $error = 'You need to enter your password twice.';
}

 

and so on for all of the conditions.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.