I tried converting this:
$regex = "/^[0-9]+[0-9\.]*(?<!\.)$/"
to all of these, but none are correct:
var regex = /^(?!\.$)[0-9]+[0-9\.]*/;
var regex = /^(?!.*\.$)[0-9]+[0-9\.]*/;
var regex = /^[0-9]+[0-9\.]*(?!\.$)/;
The PHP regex correctly rejects 1.1a and 1., but the javascript regex's do not.
Your PHP Regex may be better written as the following, which matches the same language, but is easier to read and doesn't need to use a negative look-behind:
$regex = "/^\d+(\.\d+)*$/"
It is also easy to translate it directly to a Javascript regex:
var regex = /^\d+(\.\d+)*$/;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With