RegEx for positive number + greater than zero an decimal (0.1)
问题 I want to validate a field in javascript to have at least 1 and should be positive number or decimal. Examples: 1 1.1 0.1 10.10 My current regex looks like this: var _RegEx = /^[+]?([0-9]+(?:[\.][0-9]*)?|\.[0-9]+)$/; 回答1: Simple: /^\+?(\d*[1-9]\d*\.?|\d*\.\d*[1-9]\d*)$/.test(x) Simpler: 0 < parseInt(x, 10) && parseInt(x, 10) < Infinity Simplest: 0 < +x && +x < Infinity && !/[^\d.+]/.test(x) Thanks to Jack, the last one is not so simple anymore. :/ 回答2: ^((0?0?\.([1-9]\d*|0[1-9]\d*))|(([1-9]|0