jQuery input mask

后端 未结 2 1460
说谎
说谎 2021-01-15 08:28

Hey, I am new to jQuery , I want to check onblur on input box this format cda 123 . mean first 3 characters space and 3 integers. Usually I see that code is written on Input

相关标签:
2条回答
  • 2021-01-15 09:11

    Just use some jQuery input mask plugin, for example this http://digitalbush.com/projects/masked-input-plugin/

    Then you can use:

    jQuery(function($){
        $(".InputMask-cccsnn").mask("aaa 999");   
    });
    
    0 讨论(0)
  • 2021-01-15 09:20

    You can use try using regular expressions.

    if($('input').val().match(/.{3} \d{3}$/)){
            alert('valid');
        }
        else{
            alert('invalid');
        }
    

    Check out a sample demo for your case here

    http://jsfiddle.net/ryan_s/WYzhR/1/

    0 讨论(0)
提交回复
热议问题