Monday, 8 June 2015

javascript

letters only and phone number
=====================
<script>
jQuery.validator.addMethod("lettersonly", function(value, element) {
return this.optional(element) || /^[a-z. ]+$/i.test(value);
}, "Please enter only character");

jQuery.validator.addMethod("phoneno", function(phone_number, element) {
     phone_number = phone_number.replace(/\s+/g, "");
     return this.optional(element) || phone_number.length > 9 &&
     phone_number.match(/^((\+[1-9]{1,4}[ \-]*)|(\([0-9]{2,3}\)[ \-]*)|([0-9]{2,4})[ \-]*)*?[0-9]{3,4}?[ \-]*[0-9]{3,4}?$/);
  }, "<br />Please specify a valid phone number");
</script>
===============
number exple 22.22
==================
<script>
$('.number').keypress(function (event) {
    if ((event.which != 46 || $(this).val().indexOf('.') != -1) && (event.which < 48 || event.which > 57)) {
        event.preventDefault();
    }
    var text = $(this).val();
    if ((text.indexOf('.') != -1) && (text.substring(text.indexOf('.')).length > 2)) {
        event.preventDefault();
    }
});
</script>

No comments:

Post a Comment