I am using SharePoint form field. I used regular expression for allowing only numbers not less than zero, but it is allowing alphabets and throwing error if I enter number less than zero.

function numericvalidation(validatefield, id) {

 var inputVal = id;

              var numericReg = /[^abc][^1-9]+$/;

              var isvalidinput = numericReg.test(inputVal);
              if (!isvalidinput) {
                  $("div[id*='divestimateddurationmaonths']").text(validatefield + "\n" + "must be greater than zero and  should be numeric");
                  $("div[id*='divestimateddurationmaonths']").attr("style", "color:red;font-size:13px");

              return isvalidinput;


Here is your required function

    function validatenumber(el) {
    var regex = /^[0-9]*(?:\.\d{1,2})?$/;    // allow only numbers [0-9] 
     if( !regex.test(el.value) ) {
      alert('invalid value');

Check this jsfiddle for more details

Please let me know if you have any question?

  • Please mark it as answer if it solves your query – Varun Verma Sep 1 '14 at 11:01
  • Hi,thak u I already used it but its is taking alphabets also – chiranjeevi Avala Sep 1 '14 at 11:36
  • which alphabets?? i see working fine here jsfiddle.net/qd7BL – Varun Verma Sep 1 '14 at 11:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.