cocos creator常用
1. 输入框控制输入非法字符
onEditingTextChanged (event) {
var pattern = new RegExp("^[A-Za-z0-9\u4e00-\u9fa5]+$");
//获取输入框中的值
var content = event;
var rs = "";
for (var i = 0; i < content.length; i++) {
// rs = rs + event.substr(i, 1).replace(pattern, '');
var oneStr = content.substr(i, 1);
if (pattern.test(oneStr)) {
rs = rs + oneStr;
}
}
this.editbox.string = rs;
},
网友评论