Solved

Validating TextBox text using Java Script.

Posted on 2013-06-18
5
410 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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
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…

707 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now