Solved

Validating TextBox text using Java Script.

Posted on 2013-06-18
5
414 Views
Last Modified: 2013-06-29
Hi,
This is for web form developed with .Net 3.5 and VS2010.I want to validate the text entered in Text Boxes using Java Script on submission.

It shouldn't submit to the database if entered Text contains urls,html tags,scripts and anything dangerous.

How to validate the urls,html tags,scripts using Java Script
Thanks
0
Comment
Question by:KavyaVS
5 Comments
 
LVL 4

Assisted Solution

by:MrC63
MrC63 earned 100 total points
ID: 39257713
Here's a simple way:

Create an array of strings that are not allowed, then test the text box contents against the array list.  Then use this array to test against the actual text box contents.  See the attached sample javascript.

The "Submit button would be changed to a button type (<input type=button> instead of <input type=submit>.  You would then add an onClick event that calls the TestSubmission function:

<input type="button" onClick="TestSubmission() ;" value="Save">

The array can contain any string of characters you want to test for that are not allowed during the form submission.

Hope that helps you, let me know if you need further clarification.

MrC
sample.txt
0
 
LVL 12

Assisted Solution

by:jitendra patil
jitendra patil earned 350 total points
ID: 39258959
hi kavyavs

refer the below link,
Coding techniques for protecting against Sql injection
it will help you check in your whole application's textboxes in will be always helpful
you need to add your htmlinjection text  ie(urls,html tags,scripts) in the blacklist array.
it will be once for all using Modules.

Hope this helps.
0
 
LVL 8

Assisted Solution

by:PagodNaUtak
PagodNaUtak earned 50 total points
ID: 39259086
Tip:

Validating data inputted by users using javascript alone is a very bad idea. As users of sites can disable javascript to get pass your validation.

It would be better that there is a client and server side validation.
0
 
LVL 12

Accepted Solution

by:
jitendra patil earned 350 total points
ID: 39259501
Try to implement the way i have described above as it will be coded for once and will be used in your overall application, you won't need to be calling function for each and every textbox, using module you will be doing it once and used for all.

Coding techniques for protecting against Sql injection RSS
Try the link given above, its a tested and proven approach.

Hope this helps.
0
 

Author Closing Comment

by:KavyaVS
ID: 39287597
Thanks.
0

Featured Post

Is Your AD Toolbox Looking More Like a Toybox?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
This article discusses how to create an extensible mechanism for linked drop downs.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

831 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question