Back

# Example: Validation

Use public isValidNumber method (utilising Google's libphonenumber) to validate the telephone number on the change event.

## Markup

    <input id="phone" type="tel">
    <span id="valid-msg" class="hide">✓ Valid</span>
    <span id="error-msg" class="hide">Invalid number</span>

## Code

    var telInput = $("#phone"),
      errorMsg = $("#error-msg"),
      validMsg = $("#valid-msg");

    // initialise plugin
    telInput.intlTelInput({
      utilsScript: "../../build/js/utils.js"
    });

    var reset = function() {
      telInput.removeClass("error");
      errorMsg.addClass("hide");
      validMsg.addClass("hide");
    };

    // on blur: validate
    telInput.blur(function() {
      reset();
      if ($.trim(telInput.val())) {
        if (telInput.intlTelInput("isValidNumber")) {
          validMsg.removeClass("hide");
        } else {
          telInput.addClass("error");
          errorMsg.removeClass("hide");
        }
      }
    });

    // on keyup / change flag: reset
    telInput.on("keyup change", reset);

## Result

✓ Valid Invalid number