Jump to content

Recommended Posts

You have two choices, www.php.net/REGEX or modifying the above example as so.

 

<?php
$length = strlen($input);
if(($length != 4 OR $input < 100) OR !is_numeric($input)) {
     echo "Must be 4 chars and over 100!";
}
?>

 

www.php.net/ereg

 

That is probably the better way to go is regex, but the above example should work too.

Link to comment
https://forums.phpfreaks.com/topic/50937-solved-verify-input/#findComment-250599
Share on other sites

I don't. Anytime I want something that I do not know if it exists or not I goto www.php.net and do a search.

 

For this one I searched for numeric.

 

Heck give it a try:

www.php.net

 

Search functions for numeric or number and see what comes up!

 

That is what I love about PHP the whole manual is online and easily searchable with real world examples and user contributions. There is no function that you should not be able to understand in PHP or be able to not find.

Link to comment
https://forums.phpfreaks.com/topic/50937-solved-verify-input/#findComment-250615
Share on other sites

possibly:

 

$result = preg_match('/([0-9]{4})/', $input, $matches);

 

however it wouldnt determine if the number is at least 100...

 

edit added boundaries, as would have otherwise find ANY group of 4 numbers:

 

$result = preg_match('/^([0-9]{4})$/', $input, $matches);

Link to comment
https://forums.phpfreaks.com/topic/50937-solved-verify-input/#findComment-250624
Share on other sites

had a quick play with it. not properly tested and very messy, but seems to work..?

 

<?php
$result = preg_match('/^(([0-9][1-9]|[1-9][0-9])[0-9]{2})$/', $input, $matches);
?>

 

which (i think) checks the first 2 digits to make sure that at least one of them is greater than 0 (1000 or 0100, for example)

 

seems to do everything you want.

Link to comment
https://forums.phpfreaks.com/topic/50937-solved-verify-input/#findComment-250628
Share on other sites

 

...    '/^  ...  $/'  ...

 

I snipped away all the part I understand.  What you have left is the syntax part, which is what I don't understand :P

 

'    ' <--- single quotes, as that's the string

/  / <--- why do I need those?

^    <--- what's that for?

$    <--- does that have something to do with the end of the string?

 

I've read it in the manual a dozen times, but I just can't "get it"

 

Thanks guys...

Link to comment
https://forums.phpfreaks.com/topic/50937-solved-verify-input/#findComment-250657
Share on other sites

/'s enclose the regex statement. the caret (^) signifies that we're looking from the start, the $ signifies the end of the string.

 

so in English, the regex says:

 

from the start of the string to the end, find 2 numbers that can't be both zero, as well as 2 further numbers. in all, find 4 numbers. (i think lol)

 

there's a board specifically for regex here - some of the posts/stickies may be of assistance. in my case, regex is very much about trial and error as opposed to actually knowing :D

Link to comment
https://forums.phpfreaks.com/topic/50937-solved-verify-input/#findComment-250661
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.