• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

TypeScript validator.check函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了TypeScript中validator.check函数的典型用法代码示例。如果您正苦于以下问题:TypeScript check函数的具体用法?TypeScript check怎么用?TypeScript check使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了check函数的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的TypeScript代码示例。

示例1: function

exports.calculatePrice = function(req: express.Request, res: express.Response) {
    var check = require('validator').check; // Validation
    var pages = req.query.pages,
        destination = req.query.destination,
        preferredCurrency = req.query.preferred_currency;

    if (["AUD", "EUR", "GBP", "USD"].indexOf(preferredCurrency) < 0) {
        res.send(502, {'error': "Your preferred currency is not supported"});
        return;
    }

    // Check the input
    check(pages).notNull().isInt();
    check(destination).notNull();
    check(preferredCurrency).notNull().len(1,6);

    var mailClient = new MailClient();
    mailClient.calculatePrice(pages, destination, function (error : Error, digest?: CalculatePriceDigest) {
        if (error) {
            res.send(502, {'error': error.message});
        } else {
            var finalPrice : number = (digest.priceInEur + 0.20 + BraintreeClient.guessTransactionCost(digest.priceInEur + 0.20)) * 1.27;
            var finalPriceShorted : string = finalPrice.toFixed(2);

            CurrencyConverter.convert(CurrencyConverter.convertStringToCurrencyType("EUR"), CurrencyConverter.convertStringToCurrencyType(preferredCurrency), finalPrice, function (result: number) {
                var preferredPriceShorted : string = result.toFixed(2);
                res.send({'preferredCurrency': preferredCurrency, 'priceInEur': finalPriceShorted, 'priceInPreferredCurrency': preferredPriceShorted, 'printingCity': digest.city, 'printingCountry': digest.country, 'courier': digest.courier});
            });
        }
    });
};
开发者ID:arein,项目名称:Mils-Server,代码行数:31,代码来源:letter.ts


示例2: validate

    public static validate(req: express.Request) {
        var check = require('validator').check,
            sanitize = require('validator').sanitize;

        check(req.body.pdf).notNull();
        check(req.body.recipientName).notNull();
        check(req.body.recipientAddress1).notNull();
        check(req.body.recipientCity).notNull();
        check(req.body.recipientPostalCode).notNull();
        var iso = req.body.recipientCountryIso;
        var name = req.body.recipientName;
        var company = req.body.recipientCompany;
        var address1 = req.body.recipientAddress1;
        var address2 = req.body.recipientAddress2;
        var city = req.body.recipientCity;
        var state = req.body.recipientState;
        var zip = req.body.recipientPostalCode;

        if (name.length > 50) throw  new Error("The FaxRecipient Name may not be longer than 50 characters");
        if (company != null && typeof company !== 'undefined' && company.length > 50) throw  new Error("The FaxRecipient Company may not be longer than 50 characters");
        if (address1.length > 50) throw  new Error("The FaxRecipient Address Line 1 may not be longer than 50 characters");
        if (address2 != null && typeof address2 !== 'undefined' && address2.length > 50) throw  new Error("The FaxRecipient Address Line 2 may not be longer than 50 characters");
        if (city.length > 50) throw  new Error("The FaxRecipient City may not be longer than 50 characters");
        if (state != null && typeof state !== 'undefined' && state.length > 50) throw  new Error("The FaxRecipient State may not be longer than 50 characters");
        if (zip.length > 50) throw  new Error("The FaxRecipient Zip may not be longer than 50 characters");

        // Sanitize
        req.body.recipientName = sanitize(req.body.recipientName).trim();
        req.body.recipientName = sanitize(req.body.recipientName).escape();
        req.body.recipientName = req.body.recipientName.replace("'", '').replace('"', '');

        req.body.recipientCompany = (typeof req.body.recipientCompany === 'undefined' || req.body.recipientCompany == null) ? undefined : sanitize(req.body.recipientCompany).trim();
        req.body.recipientCompany = (typeof req.body.recipientCompany === 'undefined' || req.body.recipientCompany == null) ? undefined : sanitize(req.body.recipientCompany).escape();
        req.body.recipientCompany = (typeof req.body.recipientCompany === 'undefined' || req.body.recipientCompany == null) ? undefined : req.body.recipientCompany.replace("'", '').replace('"', '');

        req.body.recipientAddress1 = sanitize(req.body.recipientAddress1).trim();
        req.body.recipientAddress1 = sanitize(req.body.recipientAddress1).escape();
        req.body.recipientAddress1 = req.body.recipientAddress1.replace("'", '').replace('"', '');

        req.body.recipientAddress2 = (typeof req.body.recipientAddress2 === 'undefined' || req.body.recipientAddress2 == null) ? undefined : sanitize(req.body.recipientAddress2).trim();
        req.body.recipientAddress2 = (typeof req.body.recipientAddress2 === 'undefined' || req.body.recipientAddress2 == null) ? undefined : sanitize(req.body.recipientAddress2).escape();
        req.body.recipientAddress2 = (typeof req.body.recipientAddress2 === 'undefined' || req.body.recipientAddress2 == null) ? undefined : req.body.recipientAddress2.replace("'", '').replace('"', '');

        req.body.recipientPostalCode = sanitize(req.body.recipientPostalCode).trim();
        req.body.recipientPostalCode = sanitize(req.body.recipientPostalCode).escape();
        req.body.recipientPostalCode = req.body.recipientPostalCode.replace("'", '').replace('"', '');

        req.body.recipientCity = sanitize(req.body.recipientCity).trim();
        req.body.recipientCity = sanitize(req.body.recipientCity).escape();
        req.body.recipientCity = req.body.recipientCity.replace("'", '').replace('"', '');

        req.body.recipientState = (typeof req.body.recipientState === 'undefined' || req.body.recipientState == null) ? undefined : req.body.recipientState;

        req.body.recipientCountryIso = (typeof req.body.recipientCountryIso === 'undefined') ? undefined : sanitize(req.body.recipientCountryIso).escape();
    }
开发者ID:arein,项目名称:Mils-Server,代码行数:55,代码来源:UploadValidator.ts


示例3: validate

    public static validate(req: express.Request) {
        var check = require('validator').check,
            sanitize = require('validator').sanitize;

        check(req.params.id).notNull();
        if (req.params.id.length !== 24) throw new Error("The ID Provided is not Correct");
        check(req.body).notNull();
        check(req.body.emailAddress).notNull().isEmail();
        check(req.body.address).notNull();
        check(req.body.creditCard).notNull();
        check(req.body.creditCard.number).notNull();
        req.body.creditCard.type = undefined; // we do not need this input
        check(req.body.creditCard.cvv).notNull();
        check(req.body.creditCard.date).notNull();
        check(req.body.address.name).notNull();
        check(req.body.address.line1).notNull();
        check(req.body.address.postalCode).notNull();
        check(req.body.address.city).notNull();
        check(req.body.address.country).notNull();
    }
开发者ID:arein,项目名称:Mils-Server,代码行数:20,代码来源:PurchaseValidator.ts



注:本文中的validator.check函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
TypeScript validator.escape函数代码示例发布时间:2022-05-25
下一篇:
TypeScript validate.js类代码示例发布时间:2022-05-25
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap