var Rx= /^(10|([1-9](\.\d+)?))$/;
This expression matches either '10',
or a string whose first character(^) must be an integer greater than zero [1-9].
This first digit
may be followed by a decimal point (\.) followed by 1 or more digits between 0 and 9 (\d+).
The $ flags the end of the string, prohibiting any invalid characters following a match.
For example-
-
function validator(field,rx){
-
var val= field.value;
-
if(rx.test(val)) return val;
-
field.value= '';
-
throw '(Invalid input in '+field.name+')\n'+field.title;
-
}
// fake an input for this test
var inputfield= {name:'oneten',value:'',title:'Type a number between 1 and 10'};
var Rx= /^(10|([1-9](\.\d+)?))$/;
inputfield.value='10.12';
alert(validator(inputfield,Rx))