Category Archives: Regular expression

Accept only numbers from user using javascript No ratings yet.

Among all browser few browsers use keyCode, others use which. If you’re using jQuery, you can reliably use which. Method 1: The below JavaScript code can be used to validate user input to accept only numbers:

  if (charCode > 31 && (charCode < 48 || charCode > 57)): This checks that the key… Read More »

Truncate string to nearest white space using Javascript No ratings yet.

Method One: Set the length. So that after the 10th character, if any space appears the string will get truncated.

Output:

  Method two:

Output:

  Method three: Using regular expresion

Output:

  Likes(0)Dislikes(0) Please rate this Sample rating item