ad

2012年6月6日 星期三

js判斷全形字(中文字)



可以寫一個funtion

String.prototype.len=function()
{ return this.replace(/[^\x00-\xff]/g,"rr").length; }
正規化判斷有幾個字元


例:
<script>
function check(){
if ($("#MonthDesc").val().len() >72) {
alert("ㄅㄧl請勿超過36個字。");
return false;
}}

String.prototype.len=function()
{ return this.replace(/[^\x00-\xff]/g,"rr").length; }

</script>