Click here to Skip to main content
15,912,400 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
Hi
I have one modal popup where there are multiple fields like address, city.
i want to restrict user to enter any html tags in that textbox.
like

test



test


etc
can any one plz give some regex to avoid/ rirestrictstrcit user to enter any html tags in that textbox
im using MVc5 , jquery

please help
Posted
Comments
F-ES Sitecore 16-Sep-15 7:09am    
A better\easier solution is to always encode data when it is rendered to the page, which razor will do for you by default. Doing this kind of qork via js is pointless as your js code can be circumvented by malicious users.

1 solution

JavaScript does that for you.
Take a look at this: http://www.c-sharpcorner.com/Blogs/12995/how-to-restrict-user-to-put-html-tag-into-textbox.aspx[^]
JavaScript
function CheckForHtmlTag(){
var reg =/<(.|\n)*?>/g; 
if (reg.test($('#myTextBox').val())) {
    var ErrorText = "Oops! HTML is not allowed.";
    alert('ErrorText');
    }
}


-KR
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900