加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

金额正则

发布时间:2020-12-14 00:39:17 所属栏目:百科 来源:网络整理
导读:var mycost = document.forms[0].mycost.valueif(mycost.length!=0){var patrn = new RegExp(/^(([1-9]d*)|0)(.d{1,2})?$/); if (!mycost.match(patrn)) { alert("金额格式不正确"); document.forms[0].mycost.focus(); return false; }} 附赠:数字正则v
var mycost = document.forms[0].mycost.value
	if(mycost.length!=0)
	{
		var patrn = new RegExp(/^(([1-9]d*)|0)(.d{1,2})?$/);
	    if (!mycost.match(patrn))
	    {
	    	alert("金额格式不正确");
	    	document.forms[0].mycost.focus();
	    	return false;
	    }
	}


附赠:数字正则var patrn = new RegExp(/^[0-9]+$/);
附赠:小写金额转成大写金额java代码
public static String numtochinese(String input){ 
		String s1="零壹贰叁肆伍陆柒捌玖"; 
		String s4="分角整元拾佰仟万拾佰仟亿拾佰仟"; 
		String temp=""; 
		String result=""; 
		if (input==null) return "输入字串不是数字串只能包括以下字符(′0′~′9′,′.′),输入字串最大只能精确到仟亿,小数点只能两位!"; 
		temp=input.trim(); 
		float f; 
		try{ 
		f=Float.parseFloat(temp); 

		}catch(Exception e){return "输入字串不是数字串只能包括以下字符(′0′~′9′,′.′),输入字串最大只能精确到仟亿,小数点只能两位!";} 
		int len=0; 
		if (temp.indexOf(".")==-1) len=temp.length(); 
		else len=temp.indexOf("."); 
		if(len>s4.length()-3) return("输入字串最大只能精确到仟亿,小数点只能两位!"); 
		int n1,n2=0; 
		String num=""; 
		String unit=""; 

		for(int i=0;i<temp.length();i++){ 
		if(i>len+2){break;} 
		if(i==len) {continue;} 
		n1=Integer.parseInt(String.valueOf(temp.charAt(i))); 
		num=s1.substring(n1,n1+1); 
		n1=len-i+2; 
		unit=s4.substring(n1,n1+1); 
		result=result.concat(num).concat(unit); 
		} 
		if ((len==temp.length())||(len==temp.length()-1)) result=result.concat("整"); 
		if (len==temp.length()-2) result=result.concat("零分"); 
		return result; 
		}

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读