Skip to main content

Posts

Showing posts from September 2, 2012

How to limit the character entry into a text box in jQuery?

Hi All,         I had come across a situation where i need to limit the character count into a text box. Suppose, your there is a requirement where the text box should take only 20 characters. In this situation preferably use the keypress method for even to happen as follows $( '#IdOfTheTextBox’ ).keypress( function (e) {               if (e.which < 0x20) { //This snippet you have to use , otherwise it will not allow you perform action using  backspace or delete button on FireFox                      return ;               }               if ( this .value.length == "20" ) {                      e.preventDefault();               }               }); By doing above, it will not allow you to enter characters after 20the character. Hope this will help . cheers Pradeepa Achar

What is "/g" in Regular expression?

Being a techno geek i was searching an answer , what is the use of "/g" in regular expression.Usually while writing regular expression we add /g at the end of the regular expression . for example, there is a regular expression     /[^a-zA-Z0-9 ]/ g .The answer is simple:  The g on the end after the  / means do a global replace - if you leave it off then only the first match will be replaced. Cheers Pradeepa achar