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.

Link to comment
Share on other sites

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.

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.