Hi, I need a regular expression that will search in a string for valid characters. The only allowed (but not mandatory to appear)characters in this string are letters,digits, # and . (period) and they can appear in any order within the string. Any other character would be invalid. All i want to do is check for valid characters and i dont care where it appears. Some valid expressions are abc123.#, abc,123#.a etc..I started off with this regex "^*[a-zA-Z0-9#*.]", but if i enter "@#$%^", this regex returns true. I also tried "^*![a-zA-Z0-9#*.]", but this forces me to have all the above characters in that string. What am i missing? I appreciate any help Thanks
The dot (".") is a meta-character that matches any character. To use the literal dot in a regexp, it needs to be escaped by a backslash. I think "^[a-zA-Z0-9#\.]*$" should do the trick. Note the $ character at the end. It is the opposite of the ^ at the beginning, and ensures that you are matching the whole string, not just a part of it at the beginning. This regexp will not match letter-like symbols like umlauts and accented letters, but I assume that's what you want.
Joined: May 02, 2002
Thanks a lot!! It worked
I’ve looked at a lot of different solutions, and in my humble opinion Aspose is the way to go. Here’s the link: http://aspose.com