Jump to content

[SOLVED] Help Please!


PrinceOfDragons

Recommended Posts

Is this an efficient way to check my form field?

 

function checkUname() {
	global $uname;

	if($this->username == "") {
		echo "Username field is blank"; $this->myErrors++;
}		elseif($uname != $_POST['username'] && $_POST['Log-In'] == "Log-In"){
		echo "Username does not exist"; $this->myErrors++;
}		elseif(strlen($this->username) < "5") {
		echo "Username is to short"; $this->myErrors++;
}		elseif(!eregi("^([0-9a-z])*$", $this->username)) {
		echo "Username is not Alphanumeric"; $this->myErrors++;			
}		elseif($uname == true && $_SESSION['create'] == "Create Account"){
		echo "Username Taken"; $this->myErrors++;

Link to comment
https://forums.phpfreaks.com/topic/169724-solved-help-please/
Share on other sites

function checkUname() {
      global $uname;
      
      if(empty($this->username)) {
         echo "Username field is blank"; $this->myErrors++;
}      elseif($uname != $_POST['username'] && $_POST['Log-In'] == "Log-In"){
         echo "Username does not exist"; $this->myErrors++;
}      elseif(strlen($this->username) < 5 || strlen($this->username) > 10) {
         echo "Username is to short"; $this->myErrors++;
}      elseif(!preg_match('/[^0-9a-zA-Z]/s', $this->username)) {
         echo "Username is not Alphanumeric"; $this->myErrors++;         
}      elseif($uname == true && $_SESSION['create'] == "Create Account"){
         echo "Username Taken"; $this->myErrors++;

 

That should be better. Eregi is deprecated so it should be preg_match. 

Link to comment
https://forums.phpfreaks.com/topic/169724-solved-help-please/#findComment-895434
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.