Regex Question

M

mavrick_101

Hi,

I'm trying to validate user input for a text field.

I do not want them to enter special characters like <, > ! @ etc.

How can I do that using Regex.

Thnx for your help.
 
A

Alexey Smirnov

Hi,

I'm trying to validate user input for a text field.

I do not want them to enter special characters like <, > ! @ etc.

How can I do that using Regex.

Thnx for your help.

Use this

^\w*$

This would allow only 0..9 and a..zA..Z (\*)

^ means beginning of the word, $ - end
 
A

Alexey Smirnov

Use this

^\w*$

This would allow only 0..9 and a..zA..Z (\*)

^ means beginning of the word, $ - end

if (Regex.IsMatch(str, @"^\w*$"))
return "Error";
 

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

Top