Jump to content

[SOLVED] Checking if its a 6 digit random number


pouncer

Recommended Posts

Explanation by parts:

^ - Matches the beginning of the string, this means that NO CHARACTERS will come before thepattern specified

[\d] - A character set to match any integer

{6} - Means to match 6 characters from the character set specified above

\z - Matches the end of the string.  This in conjunction with ^ means that only that specific pattern can be matched.  If there are any characters before or after the match, it will count as not matching.

 

This is really hard to explain, so I'll give some examples.

 

435345 - Pass - All integers

42453 - Fail - All integers, but it doesn't meet the "6" length requirement

f45235 - Fail - There are 6 characters, but they are not all integers

f435134 - Fail - There are 6 integers, but there are characters before the integers (the "f").  This is unacceptable with the use of ^

f874938u - Fail - See above.  Also, there is a character at the end, which is unacceptable with \z

 

That's the best explanation I can give you.

Explanation by parts:

^ - Matches the beginning of the string, this means that NO CHARACTERS will come before thepattern specified

[\d] - A character set to match any integer

{6} - Means to match 6 characters from the character set specified above

\z - Matches the end of the string.  This in conjunction with ^ means that only that specific pattern can be matched.  If there are any characters before or after the match, it will count as not matching.

 

This is really hard to explain, so I'll give some examples.

 

435345 - Pass - All integers

42453 - Fail - All integers, but it doesn't meet the "6" length requirement

f45235 - Fail - There are 6 characters, but they are not all integers

f435134 - Fail - There are 6 integers, but there are characters before the integers (the "f").  This is unacceptable with the use of ^

f874938u - Fail - See above.  Also, there is a character at the end, which is unacceptable with \z

 

That's the best explanation I can give you.

 

Very well said. Topic marked solved.

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.