Jump to content

Question


marcus

Recommended Posts

Is it possible to check if the same value of the submitted field are the same values?

[code]
<?php
$str = $_POST['num'];

if(strlen($str) > 0 && strlen($str) < 5){
    //then check if the field is the same value (like 4444,3333,1111)
}
?>
[/code]
Link to comment
Share on other sites

You're going to have to clarify on that a bit...

Do you mean check the length then see if the value for the length is the actual value repeated that many times????

<?php
$str = $_POST['num']
$length = strlen($str);

if(($str == $length) && ($str == str_repeat($length, $length))){
  //Condition is true
}
?>

I think that will work.

Of course that will only work on numbers under 10
Link to comment
Share on other sites

This should work to see if all characters in the field are the same:
[code]
<?php
  $str = $_POST['num'];
  $char1 = substr($str,0,1); //grabs the first character of the string
  if (preg_match("/^[$char1]*$/",$str)) { //checks to see if $str begins and ends with $char1 and only contains $char1
    //condition is true
  }
?>
[/code]

Matched these test conditions - 11111,44444,aaaaa
Didn't match these - 111211,444442,Aaaaaa
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.