How to use the isAlpha function from validator
Find comprehensive JavaScript validator.isAlpha code examples handpicked from public code repositorys.
85 86 87 88 89 90 91 92 93 94
validations.isAlpha = function isAlpha(paramName, customMessage) { return checkParam( paramName, translator(customMessage || 'isAlpha', { paramName: paramName }, locals), validator.isAlpha ) } validations.equals = validations.isEqual = function equals(
+ 5 other calls in file
GitHub: justinsisley/marshall
![justinsisley profile picture](/justinsisley.png?size=40)
211 212 213 214 215 216 217 218 219 220
case 'url': isValid = validator.isURL(stringValue, { require_protocol: true }); break; case 'alpha': isValid = validator.isAlpha(stringValue); break; case 'bool': isValid = validator.isBoolean(stringValue);
+ 31 other calls in file
50 51 52 53 54 55 56 57 58 59
} return true; }, isAlpha: function(rule, value) { if (rule) { return validator.isAlpha(value); } return true; }, isNumeric: function(rule, value) {
+ 5 other calls in file
69 70 71 72 73 74 75 76 77 78 79 80 81 82
}); // safe validators const validAlphanumeric = url => validator.isAlphanumeric(url); const validAlpha = url => validator.isAlpha(url); const validDecimal = url => validator.isDecimal(url); const validFloat = url => validator.isFloat(url);
13 14 15 16 17 18 19 20 21 22
this.isAfter = (date) => (subject) => { return StringValidator.isAfter(subject, date) ? null: subject + ' is not after ' + date; } this.isAlpha = (subject) => { return StringValidator.isAlpha(subject) ? null: subject + ' is not alpha'; } this.isAlphanumeric = (subject) => { return StringValidator.isAlphanumeric(subject) ? null : subject + ' is not alphanumeric';
+ 3 other calls in file
GitHub: mboraski/HastyMobile
8 9 10 11 12 13 14 15 16 17 18 19 20
export const sanitizeToken = dirtyToken => validator.escape(dirtyToken); export const sanitizeAndValidateName = dirtyName => { const sanitizedName = validator.escape(dirtyName); const isAlpha = validator.isAlpha(sanitizedName); return isAlpha ? sanitizedName : ''; }; export const sanitizeAndValidatePhoneNumber = dirtyPhoneNumber => {
29 30 31 32 33 34 35 36 37 38
}) const { firstName, lastName, phoneNumber, mailID} = req.body if(!validator.isEmail(mailID)){ return next(new ErrorHandler(`Input values of user are invalid.`, 400)) } if(!(validator.isAlpha(firstName) && validator.isAlpha(lastName))){ return next(new ErrorHandler(`Input values of user are invalid.`, 400)) } if(!validator.isInt(String(phoneNumber))){ return next(new ErrorHandler(`Input values of user are invalid.`, 400))
63 64 65 66 67 68 69 70 71 72
validate: { validator: function (val) { // isAlpha by default doesn't allow spaces // We need to pass an option to make it work with spaces // We enter the character we want ignored as a string or RegExp and this fixes it return validator.isAlpha(val, "tr-TR", { ignore: " " }); }, message: "Tour must only contain letters", }, // unique will throw an error if it is not met but it is technically not a data validator
1 2 3 4 5 6 7 8 9 10 11 12
const validate = (params) => { let resultado = false let name = !validator.isEmpty(params.name) && validator.isLength(params.name, { min: 3, max: undefined }) && validator.isAlpha(params.name, "es-ES") let nick = !validator.isEmpty(params.nick) && validator.isLength(params.nick, { min: 2, max: 60 })
+ 3 other calls in file
8 9 10 11 12 13 14 15 16 17
required: [true, 'User must have a name!'], trime: true, maxlength: [20, 'Name should smaller then 20 Character'], validate: { validator: function (v) { return validator.isAlpha(v, 'en-US', { ignore: ' ' }); }, message: `Name should conains only valid alphabates!`, }, },
+ 11 other calls in file
53 54 55 56 57 58 59 60 61 62
creatUser: async (req, res) => { try { if ((validator.equals(req.body.gender, "mr") || validator.equals(req.body.gender, "mrs")) && validator.isAlpha(req.body.name) && validator.isAlpha(req.body.firstname) && req.body.cookie) { if (!validator.isEmail(req.body.email)) { res.status(401).send({ message: 'The format of the email is wrong' }); return;
+ 3 other calls in file
GitHub: mert-izgahi/go-trip
9 10 11 12 13 14 15 16 17 18
type: String, required: [true, "First name is required value"], minLength: [3, "Min length of first name is 3"], validate: { validator: function (val) { return validator.isAlpha(val); }, message: "Last name should contain only alpha chars,{VALUE}", }, },
+ 3 other calls in file
0 1 2 3 4 5 6 7 8 9 10 11
const validator = require('validator'); const validate = (params) => { let name = !validator.isEmpty(params.name) && validator.isLength(params.name,{min: 2, max: undefined}) && validator.isAlpha(params.name, 'en-US'); let surname = !validator.isEmpty(params.surname) &&
+ 7 other calls in file
GitHub: Dikfield/Natours-API
10 11 12 13 14 15 16 17 18 19
maxlength: [20, 'A user nickname must have less or equal then 40 char'], minlength: [3, 'A user nickname must have more or equal then 10 char'], validate: { validator: function (val) { const valNoSpaces = val.split(' ').join(''); return validator.isAlpha(valNoSpaces, 'en-GB'); }, message: 'A user nickname must only contain characteres', }, },
10 11 12 13 14 15 16 17 18 19 20 21 22
} // Validate name exports.validateName = (name) => { return validator.isAlpha(name) && validator.isLength(name, { min: 2 }); } // Validate phone number exports.validatePhone = (phone) => {
83 84 85 86 87 88 89 90 91 92
let full_name = req.body.full_name let born_date = req.body.born_date let email = req.body.email let user_password = req.body.user_password let is_full_name_OK = validator.isAlpha(full_name, ['pt-BR'], { ignore: acceptableCharacters.inName }) let is_email_OK = validator.isEmail(email) let is_born_date_OK = validator.isDate(born_date)
+ 3 other calls in file
validator.escape is the most popular function in validator (548 examples)