473,378 Members | 1,319 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

TextBox validation using regex

103 100+
Hi,

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=(document.getElementById('txtEnter')).value;

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

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

and

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("error");

else
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.

Mathew.
Oct 2 '08 #1
2 3427
gits
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';
  2.  
  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

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

Similar topics

21
by: Stefan Richter | last post by:
Hi, after coding for days on stupid form validations - Like: strings (min / max length), numbers(min / max value), money(min / max value), postcodes(min / max value), telefon numbers, email...
10
by: Dave | last post by:
I can't get a number out of my textbox. it keeps giving me an error and saying that the input string was not in the correct format. this.number = int.Parse((this.numberTextBox.Text.ToString()); ...
2
by: live your lives | last post by:
i am trying to validate a simple username textbox using RegularExpressionValidator: TextBox tbUserName = new TextBox(); tbUserName.ID = "tbUserName"; string strPatternUserName = @"\W"; //...
1
by: Newbie | last post by:
i have a textbox in a c# asp.net webform. i am using a regularexpressionvalidator control to validate the textbox. only numbers are allowed in it. in my regularexpressionvalidator control property...
4
by: Bernie Yaeger | last post by:
I'm building a custom textbox for numbers only (actually two of them - one for integers and one that allows currency entries, but let's discuss the integer only control). I'm having a problem...
11
by: Keith | last post by:
I apologize for those of you who think I'm posting on the same topic. It is not that I don't appreciate all of your comments - and I'm definitely reading them all - but I think I have a differing...
1
by: Jim Dornbush | last post by:
Has anyone seen an updated regex expression from Microsoft for the email validation expression so that single quotes are allowed? I've been using the canned regex for emails, but recently been...
11
by: Rik | last post by:
Hello guys, now that I'm that I'm working on my first major 'open' forms (with uncontrolled users I mean, not a secure backend-interface), I'd like to add a lot of possibilities to check wether...
1
by: vayalumkan | last post by:
I have the following program (C# VS 2005) for validating an email id entered in a textbox. It works fine. Namespace used - using System.Text.RegularExpressions; At present I have written...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.