How can I keep html code out of my forms?
November 6th, 2009 | by admin |I’ve a mail form on my website and I’m wondering how I can validate what is put into the message part of my form so that I can keep html code out of it.
Can you help me with some code to strip out html code from my form?
use javascript to exclude special characters like < and >. Check out the source. Ignore the message the guy wrote, the javascript you see should work. Just tweak it to your needs.
Tags: Code Html, Form Javascript, html code, Html Forms, Html Javascript, Lt, Mail Form
By 11OhMan04 on Nov 7, 2009
use javascript to exclude special characters like < and >. Check out the source. Ignore the message the guy wrote, the javascript you see should work. Just tweak it to your needs.
References :
http://www.eggheadcafe.com/community/aspnet/3/10062951/validating.aspx
By limniadblue on Nov 7, 2009
Use the jquery validation plug in, I use it on every form I code.
It spits out nice messages if people don’t fill out inputs properly.
http://docs.jquery.com/Plugins/Validation
Add the latest jquery and the validation plugin in your header:
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3/jquery.min.js"></script>
<script type="text/javascript" src="jquery.validate.min.js"></script>
Then add the script to suit your specific form, for example:
<script id="demo" type="text/javascript">
$(document).ready(function() {
$("#yourFormID").validate({
rules: {
Name: "required",
Company: "required",
Title: "required",
Phone: "required",
Email: {
required: true,
email: true
},
Comments: "required"
},
messages: {
Name: "Please enter your name",
Company: "Please enter your company",
Title: "Please enter your title",
Phone: "Please enter your phone number",
Email: "Please enter a valid email address",
Comments: "Please enter your comments"
}
});
});
</script>
It looks like you might be able to get ride of certain characters (code) using the removeAttrs( attributes ) option or addMethod to write your own function to make code characters invalid.
References :
Me – developer
http://jquery.com/
By Sean C on Nov 7, 2009
To strip HTML tags you can use the .replace() method and a regular expression. I suggest you find a good Reference book on Javascript and study the language a bit more before continuing. Without more detailed information on how/where you want this done, not many can help you.
Good Luck!
Sean Colicchio
Server Engineer
Host My Site
http://www.hostmysite.com/?utm_source=bb
References :