Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Validating TextBox text using Java Script.

Posted on 2013-06-18
5
Medium Priority
?
430 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
5 Comments
 
LVL 4

Assisted Solution

by:MrC63
MrC63 earned 400 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 13

Assisted Solution

by:Jitendra Patil
Jitendra Patil earned 1400 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 200 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 13

Accepted Solution

by:
Jitendra Patil earned 1400 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

This article discusses the difference between strict equality operator and equality operator in JavaScript. The Need: Because JavaScript performs an implicit type conversion when performing comparisons, we have to take this into account when wri…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
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…

688 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