10 examples of 'name validation in javascript only alphabets' in JavaScript

Every line of 'name validation in javascript only alphabets' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your JavaScript code is secure.

All examples are scanned by Snyk Code

By copying the Snyk Code Snippets you agree to
this disclaimer
75function validateName(name) {
76 var result = {
77 hasViolation: false,
78 message: ''
79 };
80
81 if (name === '') {
82 result.hasViolation = true;
83 result.message = (parameters.isSet ? 'Set' : 'Pointer') + ' must have a non-empty name.';
84 } else if (parameters.notAllowedNames.indexOf(name) > -1) {
85 result.hasViolation = true;
86 result.message = 'Name "' + name + '" is already used for a ' +
87 (parameters.isSet ? 'pointer' : 'set') + ' or ' + 'an aspect.';
88 } else if (REGEXP.DOCUMENT_KEY.test(name) === false) {
89 result.hasViolation = true;
90 result.message = 'Name "' + name + '" contains illegal characters, it may not contain "." ' +
91 'or start with "$" or "_".';
92 } else {
93 if (_endsWith(name, CONSTANTS.CORE.COLLECTION_NAME_SUFFIX)) {
94 result.hasViolation = true;
95 result.message = 'Name "' + name + '" ends with "' + CONSTANTS.CORE.COLLECTION_NAME_SUFFIX + '", ' +
96 'which could lead to collisions with data stored for inverse pointers.';
97 } else if (name === CONSTANTS.CORE.BASE_POINTER) {
98 result.hasViolation = true;
99 result.message = 'Name "' + CONSTANTS.CORE.BASE_POINTER + '" is reserved for base/instance ' +
100 'relationship.';
101 } else if (name === CONSTANTS.CORE.MEMBER_RELATION) {
102 result.hasViolation = true;
103 result.message = 'Name "' + CONSTANTS.CORE.MEMBER_RELATION + '" is reserved for ' +
104 'set membership.';
105 } else if (name === CONSTANTS.CORE.OVERLAYS_PROPERTY) {
106 result.hasViolation = true;
107 result.message = 'Name "' + name + '" is a reserved key word.';
108 }
109
110 if (parameters.isSet && (name === 'src' || name === 'dst')) {
111 result.hasViolation = true;
112 result.message = 'Name "' + name + '" can only be used for pointer names and not for sets.';
113 }
114 }
115
116 return result;
117}
Important

Use secure code every time

Secure your code as it's written. Use Snyk Code to scan source code in minutes – no build needed – and fix issues immediately. Enable Snyk Code

45function validateName (name) {
46 const $field = document.querySelector('#name').parentNode;
47 if (!name) {
48 $field.setAttribute('data-invalid', "Name is Required")
49 return false
50 }
51
52 if (/\s/.test(name)) {
53 $field.setAttribute('data-invalid', "A name can't have white space")
54 return false
55 }
56 return true
57}
13static isName(name) {
14 if ( !isEmpty(name) && matches(name, /^[0-9a-z \']+$/i)) return true;
15 else return false;
16}
735function validate(name) {
736 return !error(name) ? name : null;
737}
106function isValidName(name) {
107 return NAME_REG_EXP.test(name);
108}
66validateName(name) {
67 if (~this.reservedKeys.indexOf(name)) {
68 throw new Error(`Field name ${name} is a reserved key`);
69 }
70}
62validateName(name: string) {
63 if (name.length > 255) {
64 return translate('onboarding.create_project.display_name.error');
65 }
66 return undefined;
67}
1function valid_name(e) {
2 /* 50 Characters or less, following are not allowed: ' , + */
3 // TODO - Wait, do we really not allow single quotes? I forget
4 var re_name = new RegExp("[+\',]", "g");
5
6 if (e.value.length > 50 || re_name.test(e.value)) {
7 e.style.color='#F00';
8 } else {
9 e.style.color='#000';
10 }
11}
180function __isValidName__(name) {
181 // test if name contains only valid characters
182 return name.match(re_validName);
183}
1226function isValidName(str) {
1227 return /^[_a-zA-Z0-9-]+$/.test(str);
1228}

Related snippets