Regular expression

  • Thread starter Thread starter TAB
  • Start date Start date
T

TAB

Hi

I'm struggling with a regex that will check for 0-1 in a string of 1-8
characters,
as in a binary string.
Most examples I've seen checks a pattern in a complete string but I would
like to
check every input by TextBox_TextChanged event that means the string could
vary from
1 to 8 characters.

So far I'm managed to check the first char, but then it also accepts 2-9.

Any help appreciated.
 
TAB said:
I'm struggling with a regex that will check for 0-1 in a string of 1-8
characters,
as in a binary string.
Most examples I've seen checks a pattern in a complete string but I would
like to
check every input by TextBox_TextChanged event that means the string could
vary from
1 to 8 characters.

So far I'm managed to check the first char, but then it also accepts 2-9.

Any help appreciated.

If I understood correctly, you want a regular expression that will verify
that a string is made out of one to eight ones or zeroes. In that case, I
believe that the following expression will do the job (untested):

"^[01]{1,8}$"
 
Yes it does, thanks a lot.

Alberto Poblacion said:
TAB said:
I'm struggling with a regex that will check for 0-1 in a string of 1-8
characters,
as in a binary string.
Most examples I've seen checks a pattern in a complete string but I would
like to
check every input by TextBox_TextChanged event that means the string
could vary from
1 to 8 characters.

So far I'm managed to check the first char, but then it also accepts 2-9.

Any help appreciated.

If I understood correctly, you want a regular expression that will
verify that a string is made out of one to eight ones or zeroes. In that
case, I believe that the following expression will do the job (untested):

"^[01]{1,8}$"
 
Back
Top