-5

Need to restrict entering alphabets and special characters in a textbox using jquery. Need to enter only numbers. How to implement using keypress() functionality in jquery for a text box in jsf?.

Code :

      <table>
         <tr>
          <h:inputlabel value="Actual"></h:inputlabel>
           <td>
              <h:inputtext id="Actual" styleClass="input-tex" value="#bean.customer"></h:inputtext>
            <td>
         </tr>
       <table>

Any help is appreciated.

3
  • You can parse it into int and check Commented Mar 20, 2013 at 17:02
  • Can you post the code of your current implementation you are having issues with so we can have a look at it please? Commented Mar 20, 2013 at 17:02
  • 1
    have you tried to search for the answer first ? stackoverflow.com/questions/891696/… Commented Mar 20, 2013 at 17:02

2 Answers 2

0

you can try this in onkeypress function

function validateDigits(){
    var str = "54665";
var re = /^\d+$/;
alert(str.match(re)!=null);
}

it returns true in case it validate successfully otherwise returns false

Sign up to request clarification or add additional context in comments.

Comments

0

I'm sure there's a more elegant way, but I use:

    $('#parentobject').on('keypress', '#inputid', function (e) {
        if (isNaN(e.currentTarget.value) == true) {
            var textlen = $(this).val().length;

            $(this).val($(this).val().substring(0, (textlen - 1)));

            return false;
        }
    });

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.