Limiting to a Specific Set of Characters in Regex Not Working

I need to validate a string to allow only a specific set of characters using regex. Unfortunately, I am stuck using regex only for the validation of these strings.

Anyways I need to limit a string to allow only the following characters: a-z and A-Z and 0-9 and space and .,;:!=+-_

For this I have created the following expression:

[a-zA-Z0-9.,;:!=+-_\s]*

I can't figure out why this expression is not working. The following test strings when I am using this are giving me the following results:

<test> Valid 
$<test> Invalid 
test Valid 
<test>asdf</test> Invalid

It appears the order of these special characters is being taken into account when really all I need to to limit the validation to a specific list of valid characters regardless of the order in the string.

Can anyone shed some light on why this may be allowing special characters such as '<>' but only in certain orders?

Answers


use anchors and shild symbol -

^[a-zA-Z0-9.,;:!=+\-_\s]*$


Need Your Help

CSS - Navigation

css html5 navigation

I'm having an issue with the navigation links in my navbar. To start off, it's not aligned in the middle of the navigation bar as shown here:

Why won't my solution work to P/Invoke NotifyServiceStatusChange in C#?

c# .net winapi pinvoke

I am trying to P/Invoke the NotifyServiceStatusChange event in C# to check when a service has stopped. I managed to get it to compile and run without any errors, but now, when I stop the service, it

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.