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
https://forums.phpfreaks.com/topic/232216-control-form-input/
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
https://forums.phpfreaks.com/topic/232216-control-form-input/#findComment-1194577
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
https://forums.phpfreaks.com/topic/232216-control-form-input/#findComment-1194595
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
https://forums.phpfreaks.com/topic/232216-control-form-input/#findComment-1194597
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.