当用户输入卡号时,每间隔四位补个空格的正则式怎么写???
keyup是检查 ? 补空格怎么写 ?

解决方案 »

  1.   

    用的keyup事件
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
    <title></title>
    </head>
    <body >
    <input type='text' onkeyup='xx(this,this.value)'>
    <script language="javascript">
    function xx(o,s){
    o.value=s.replace(/([^\s]{4}(?!\s))/g,'$1 ');
    }
    </script>
    </body>
    </html>
      

  2.   

    o.value=s.replace(/([^\s]{4}(?!\s|$))/g,'$1 ');