Restrict user from entering Comma and Semicolon in TextBox using JavaScript

Last Reply 3 months ago By dharmendr

Posted 3 months ago

I need to restrict user to enter comma and semicolon in textbox while typing itself it should not accept comma and semicolon in text box how can i do this 

You are viewing reply posted by: dharmendr 3 months ago.
Posted 3 months ago

Hi nalinid93,

Refer below sample example.

Enter value:
<input type="text" id="text1" onkeypress="return RestrictCommaSemicolon(event);"
    ondrop="return false;" onpaste="return false;" />
<script type="text/javascript">
    function RestrictCommaSemicolon(e) {
        var theEvent = e || window.event;
        var key = theEvent.keyCode || theEvent.which;
        key = String.fromCharCode(key);
        var regex = /[^,;]+$/;
        if (!regex.test(key)) {
            theEvent.returnValue = false;
            if (theEvent.preventDefault) {


I agree, here is the link: