regular expression problem

K

kieran

Hi,

I want to create a regular expression on a web form that allows the
user to input a maximum of 7 characters (these characters can be either
letters or numbers) but no full stops.

I cant seem to get this right.

Any input or simple regular expression tutorials appreciated.

Thanks.
 
S

Samuel Shulman

I think that you can use the text_changed event (that will be server side
processing)

btw, this is VB group not ASP

hth,
Samuel Shulman
 
B

Branco Medeiros

kieran wrote:
I want to create a regular expression on a web form that allows the
user to input a maximum of 7 characters (these characters can be either
letters or numbers) but no full stops.
<snip>

Regardless of where and how you'd use the regex, I guess you can use
the following, which will match 1 up to seven alphanumeric chars:

Function IsValidInput(ByVal Text As String) As Boolean
Return System.Text.RegularExpressions.Regex.IsMatch( _
Text, "^(\w|\d){1,7}$" _
)
End Function

The regex above will match the whole string (the "^" requires that the
match begins at the begining of the string, and the "$" requires that
the match ends at the end of the string). It will match 1 to 7
occurrences (the "{1, 7}" operator) of letters ("\w") or digits ("\d").

HTH.

Regards,

Branco.
 
K

kieran

cheers Branco...




Branco said:
kieran wrote:

<snip>

Regardless of where and how you'd use the regex, I guess you can use
the following, which will match 1 up to seven alphanumeric chars:

Function IsValidInput(ByVal Text As String) As Boolean
Return System.Text.RegularExpressions.Regex.IsMatch( _
Text, "^(\w|\d){1,7}$" _
)
End Function

The regex above will match the whole string (the "^" requires that the
match begins at the begining of the string, and the "$" requires that
the match ends at the end of the string). It will match 1 to 7
occurrences (the "{1, 7}" operator) of letters ("\w") or digits ("\d").

HTH.

Regards,

Branco.
 

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