开发者

custom parser for digits and characters

开发者 https://www.devze.com 2023-02-02 17:26 出处:网络
Hi I would like to开发者_运维百科 write a parser like the one below except I would like it to take characters with the the digits like 345j, 982p0. What would I change to be able to have characters wi

Hi I would like to开发者_运维百科 write a parser like the one below except I would like it to take characters with the the digits like 345j, 982p0. What would I change to be able to have characters with numbers?

ts.addParser({
    id: "digit",
    is: function (s, table) {
        var c = table.config;
        return $.tablesorter.isDigit(s, c);
    },
    format: function (s) {
        return $.tablesorter.formatFloat(s);
    },
    type: "numeric"
});


Assuming you want to allow any combination of letters and/or numbers, but nothing else, you could use a regular expression:

ts.addParser({
    id: "alphanumeric",
    is: function(s, table) {
        return /^[a-z0-9]*$/i.test(s);
    },
    format: function(s) {
        return s;
    },
    type: "text"
});

The regular expression is /^[a-z0-9]*$/i, which matches any combination of only a-z and 0-9, case-insensitive. I changed your format function as well, since you can't parse this as a float, and change the name and type to reflect the changes in the parser.

0

精彩评论

暂无评论...
验证码 换一张
取 消