0

I have tried with below code. the code only validating "yourname". yourlname and umobile not validating. Please let me know the mistake which I have done in the code.

if(strlen($yourname)<4) 
{
    $output = json_encode(array('type'=>'error', 'text' => 'Name is too short!'));
    die($output);
}
if(strlen($yourlname)) 
{
    $output = json_encode(array('type'=>'error', 'text' => 'Please enter Last Name'));
    die($output);
}

if(strlen($umobile)) 
{
    $output = json_encode(array('type'=>'error', 'text' => 'Please enter Mobile Number'));
    die($output);
}
2
  • 1
    strlen Returns the length of a string on success, and 0 if the string is empty and you always enter in if condition. Instead use !empty($yourlname){} Commented May 24, 2016 at 6:43
  • Because the condition its validating fine is the only correct one you have Commented May 24, 2016 at 6:45

1 Answer 1

1

Use like this

  if(!strlen(trim($yourlname)))

And

 if(!strlen(trim($umobile)))
Sign up to request clarification or add additional context in comments.

1 Comment

I can't able to click on that,

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.