Core: Allow negative decimal with no 0 (#2483)

* Core: Allow negative decimal with no 0

* Update regex

---------

Co-authored-by: METALCOMPINC\cstieg <cstieg@metalcompinc.com>
Co-authored-by: Kieran <kieran.brahney@gmail.com>
This commit is contained in:
Christopher Stieg
2024-06-29 06:11:15 -04:00
committed by GitHub
parent 75f51237e4
commit e837cc49be
2 changed files with 2 additions and 1 deletions

View File

@@ -1485,7 +1485,7 @@ $.extend( $.validator, {
// https://jqueryvalidation.org/number-method/
number: function( value, element ) {
return this.optional( element ) || /^(?:-?\d+|-?\d{1,3}(?:,\d{3})+)?(?:\.\d+)?$/.test( value );
return this.optional( element ) || /^(?:-?\d+|-?\d{1,3}(?:,\d{3})+)?(?:-?\.\d+)?$/.test( value );
},
// https://jqueryvalidation.org/digits-method/

View File

@@ -177,6 +177,7 @@ QUnit.test( "number", function( assert ) {
assert.ok( method( "123,000.00" ), "Valid decimal" );
assert.ok( method( "-123,000.00" ), "Valid decimal" );
assert.ok( method( ".100" ), "Valid decimal" );
assert.ok( method( "-.100" ), "Valid decimal" );
assert.ok( !method( "1230,000.00" ), "Invalid decimal" );
assert.ok( !method( "123.0.0,0" ), "Invalid decimal" );
assert.ok( !method( "x123" ), "Invalid decimal" );