471,887 Members | 865 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,887 software developers and data experts.

TextBox validation using regex

103 100+

I am trying to check whether the textbox contains single quote,double quote and < and > symbols.

I got the regex to check all the requirements.
its as shown below.


str.match(/([\<\])(1,))* ([\>])/)==null (for checking < and > symbol)

str.match(["'"])==null (for checking single quote)


str.match(['"'])==null) (for checking double quotes.)

Now i give all these conditions as

if(str.match(/([\<\])(1,))* ([\>])/)==null && str.match(["'"])==null && (str.match(['"'])==null))


alert("no error");

It works fine.

In the above code i used str.match() three times. I need to use str.match() only one time and need to check whether the textbox contains < or > or single quote or double qoute.

Please help me..

Thanks in Advance.

Oct 2 '08 #1
2 3313
5,390 Expert Mod 4TB
here is a short example ... you may just use the | for the OR :)

Expand|Select|Wrap|Line Numbers
  1. var s = 'fo\'o';
  3. alert(/[<]|[>]|[']|["]/g.test(s)); 
kind regards

PS: and please use the code-tags when posting source code.
Oct 2 '08 #2
rnd me
427 Expert 256MB
if you are trying to remove html, you'd better be a lot more thoughtful than the regexps i see posted unless you also validate on the server.

there's more than one way to say <script, onclick="alert('bad')", etc...

check out the xss cheatsheet for more info.
Oct 2 '08 #3

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

21 posts views Thread by Stefan Richter | last post: by
10 posts views Thread by Dave | last post: by
2 posts views Thread by live your lives | last post: by
1 post views Thread by Newbie | last post: by
11 posts views Thread by Keith | last post: by
1 post views Thread by Jim Dornbush | last post: by
11 posts views Thread by Rik | last post: by
reply views Thread by YellowAndGreen | last post: by
reply views Thread by zermasroor | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.