473,814 Members | 3,131 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

TextBox validation using regex

103 New Member
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.g etElementById(' txtEnter')).val ue;

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 3452
gits
5,390 Recognized Expert Moderator Expert
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 Recognized Expert Contributor
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
3928
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 adresses and so on. I thought it might be a better way to programm an automated, dynamic form validation that works for all kinds of fields, shows the necessary error messages and highlights the coresponding form fields.
10
9116
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()); How do I get the number out of the text box if I only entered small positive integers? dave
2
8112
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"; // i've tried using "\\W", "\w", "\\w","@\w", "/\\w", etc... // but it always prints my error msg UNLESS the textbox is set to "". // why does this not work?
1
318
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 window, i couldnt find the right validation expression to use to make it work properly. thanks in advance.
4
1169
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 knowing where in the current string the user is trying to enter '-' (ascii 45). I have been able to ensure it can't be entered twice, but I currenty only allow it at all when the string length is zero. However, if the user enters '345' and now wants...
11
4584
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 opinion of how I want to handle the 'user experience' in the application I'm creating. While I know I could allow the user to enter in number and alpha text - in a text box - and then tell them when the execuate a command "This is not numeric data", I...
1
1955
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 informed by a customer that the single quote is allowed as part of the email address (Mr. O'Leary). I prefer using the un-modified version from the framework, but will update my local code regardless.
11
3004
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 certain fields match certain criteria, and inform the user in different ways when the data is wrong (offcourse, this will be checked on posting the data again, but that's something I've got a lot of experience with). Now, offcourse it's...
1
2640
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 the functionality inside textBox1_Validating event as shown below and when I click button1(my form contains button control called button1), it is giving me the perfect output. private void textBox1_Validating(object sender, CancelEventArgs e)
0
9609
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10669
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10408
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10426
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9225
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7686
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6897
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5570
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
3886
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.