js常用方法总结
1.trim字符串前后空格
function trim(str) { // trim字符串前后空格 return str.replace(/(^\s*)|(\s*$)/g, ''); }
2.判断字符串是否为null
function isNull(str) { // 判断字符串是否为null if (typeof str == 'undefined' || str === null) { return true; } else { return false; } }
3.判断字符串是否为空
function isBlank(str) { // 判断字符串是否为空 if (typeof str === 'undefined' || str === null || trim(str) === '') { return true; } else { return false; } }
4.判断字符串是否全为数字
function(str) { // 判断字符串是否全为数据 if (typeof str === 'undefined' || str === null || trim(str) === '') { return false; } if (!(/^\d*$/g).test(str)) { return false; } return true; }
未完待续