Show validators (regular expression)

Shows how to validate text, in this case textinput is val There are two examples. First validate2To5Int where the criteria is positive integer values. The input value has to be between 2 and 5 digits. Secondly, validateMoney4Decimals1 is the criteria that the input has to be from 1 to 4 digits, and the input can be either positive or negative. The example, the button click shows a call to validateMoney4Decimals1
$("#btnClick").click(function () { var val = $("#txtMine").val(); // var res = validate2To5Int(val); var res = validateMoney4Decimals1(val); $("#result").text(res); }); function validate2To5Int(data) { var regex = "^[0-9]{2,5}"; var totest =data; var x =totest.match(regex); if (x!=null && x.length >0 && x[0] === totest) return "OK data"; else return "invalid data"; } function validateMoney4Decimals1(data) { var regex = "^\-{0,1}[0-9]{1,4},[0-9]{1,2}$|^\-{0,1}[0-9]{1,4}$"; var totest =data; var x =totest.match(regex); if (x != null && x.length > 0 && x[0] === totest) return "OK data (" + new Date().getSeconds()+")"; else return "invalid data (" + new Date().getSeconds()+")"; }