3

I'm new to Jquery. I'm just trying to add only one single decimal value in a textbox using Regex. As it allows ".". But, I need to restrict to only one ".". Can any one suggest me in doing that? Any help would be greatly appreciated.

My code is :

$("#cashReceived").filter_input({regex:'[0-9-.]'});

Thank you.

1

2 Answers 2

1

If you're using this plugin, you can't. You'd better find another library/plugin.

Reason: The plugin checks character by character (unless the user copy&paste the text).

Related part from the code:

...
if (event.type=='keypress') {

  var key = event.charCode ? event.charCode : event.keyCode ? event.keyCode : 0;

  ...

  var string = String.fromCharCode(key);
  ...

if (regex.test(string)) {
Sign up to request clarification or add additional context in comments.

Comments

1

You can use this regex to allow only max but optional decimal point:

$("#cashReceived").filter_input({regex:'[-+]?[0-9]+(\\.[0-9]+)?'});

1 Comment

Are you able to produce a JSFIDDLE with your problem? You can also try this regex:'[0-9]+\\.[0-9]+'

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.