jquery plugin filtering form field inputs with regex for decimal/float values - validated regex patterns dont seem to be working

Viewed 258

Background: using JQuery plugin for input text field filtering and regex (tried several variations actually) with symfony 3.x

jquery http://www.thimbleopensource.com/tutorials-snippets/jquery-plugin-filter-text-input

Goal: Have the form field accept only positive float / decimal up to 3 decimal places.

Acceptable:

3.24
.56
3456.789

Not Acceptable:

-3.65
-.67
3.6.5
3c.56
5g

I have used reg exp testers such as https://www.freeformatter.com/regex-tester.html to build/find a reg ex that works such as;

^(?:[1-9]\d*|0)?(?:\.\d+)?$ or ^[0-9]*[.][0-9]+$

Both work in the tester.

I am using regex like;

$('#name of the form field').filter_input({regex: "^[0-9]*[.][0-9]+$"});

They don't seem to work with the jquery plugin. The plugin might be buggy or am I doing something wrong?

2 Answers
Related