web前端js中随机生成指定位数的字母数字、组合字符串可选择字母大小写

$rootScope.randomString = "";
$scope._getRandomString = function(len){
    len = len || 32;
    var $chars = 'ABCDEFGHJKMNPQRSTWXYZabcdefhijkmnprstwxyz2345678'; // 默认去掉了容易混淆的字符oOLl,9gq,Vv,Uu,I1
    var maxPos = $chars.length;
    var pwd = '';
    var num = '';
    for (i = 0; i < len; i++) {
        pwd += $chars.charAt(Math.floor(Math.random() * maxPos));
        num+=Math.floor(Math.random()*10);
    }
    pwd.toLowerCase();
    $rootScope.randomString = pwd+num;
    return pwd;
}

另附字母转换大小写:

"ABC".toLowerCase()//转小写
"abc".toUpperCase()//转大写



你可能感兴趣的:(web前端开发)