Regular expression

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.
 
A

Alberto Poblacion

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}$"
 
T

TAB

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}$"
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top