ASP.NET - What is the regular expression that should not accept ">" and "<" characters.

Asked By Vamsi n on 20-Feb-13 08:41 AM
what is the regular expression that accepts all alphanumeric and all special characters except only greaterthan(>) and lessthan(<) characters.

Danasegarane Arunachalam replied to Vamsi n on 21-Feb-13 03:43 AM
Here is the sample code

<html xmlns="">
<script type="text/javascript">
var alphanumeric = /[\sA-Z,a-z,1234567890!]/g;

function restrictCharacters(myfield, e, restrictionType) {
    if (!e) var e = window.event
    if (e.keyCode) code = e.keyCode;
    else if (e.which) code = e.which;
    var character = String.fromCharCode(code);

    // if they pressed esc... remove focus from field...
    if (code==27) { this.blur(); return false; }
    // ignore if they are press other keys
    // strange because code: 39 is the down key AND ' key...
    // and DEL also equals .
    //if (!e.ctrlKey && code!=9 && code!=8 && code!=36 && code!=37 && code!=38 && (code!=39 || (code==39 && character=="'")) && code!=40) {
    if (!e.ctrlKey && code!=9 && code!=8 ) {
        if (character.match(restrictionType)) {
            return true;
        } else {
            return false;

<form action="" method="get">

<p><label for="input3">alphaOnly</label> <input type="text" id="input3" onkeypress="return restrictCharacters(this, event, alphanumeric);" /></p>


Add values to according to your need

var alphanumeric = /[\sA-Z,a-z,1234567890!]/g;