本文整理匯總了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});
});
}
});
};
示例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();
}
示例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();
}