How to use invalidString method in wpt

Best JavaScript code snippet using wpt

bs4-form-validation.js

Source:bs4-form-validation.js Github

copy

Full Screen

1/*2 Instructions and info at: https://github.com/colmeye/BS4-Form-Validation3*/4class Validation5{6 constructor(formId)7 {8 // Form globals9 this.form = $("#" + formId);10 this.submitButton = $(this.form).find('input[type="submit"]');11 this.submitButtonText = this.submitButton.val();12 // Global input array13 this.inputLog = [];14 // Basic css classes15 this.validC = "is-valid";16 this.invalidC = "is-invalid";17 // Enables submit listener18 this.checkAll();19 }20 ////////////////////21 // Main Functions //22 ////////////////////23 /*24 The functions in this category are called by developers to add a responsive layer of form validation25 */26 /*27 Make a general text input required for form submission.28 */29 requireText(inputId, minLength, maxLength, illegalCharArray, necessaryCharArray)30 {31 let input = $("#" + inputId);32 let invalidString = "";33 // Create requried *34 this.createAsterisk(input);35 // Add this input to the input log, for easy check alls36 this.inputLog.push(["requireText", inputId, minLength, maxLength, illegalCharArray, necessaryCharArray]);37 38 // Check string for issues while editing39 $(input).on('input focus', input, () =>40 {41 // Append any invalid issues to string when editing42 invalidString = "";43 invalidString += this.lengthCheck(input, minLength, maxLength);44 invalidString += this.illegalCharCheck(input, illegalCharArray);45 this.showWarning(input, inputId, invalidString);46 });47 // Enable submit again on an input change48 $(input).on('input', input, () =>49 {50 this.submitDisabled(false, this.submitButtonText);51 });52 // Check string for issues after editing53 $(input).on('focusout', input, () =>54 {55 invalidString += this.necessaryCharCheck(input, necessaryCharArray);56 this.showWarning(input, inputId, invalidString);57 // Remove green border58 this.removeValid(input);59 });60 return invalidString;61 }62 /*63 Same as require string, but also regex for proper email 64 */65 requireEmail(inputId, minLength, maxLength, illegalCharArray, necessaryCharArray)66 {67 let input = $("#" + inputId);68 let invalidString = "";69 // Create requried *70 this.createAsterisk(input);71 // Add this input to the input log, for easy check alls72 this.inputLog.push(["requireEmail", inputId, minLength, maxLength, illegalCharArray, necessaryCharArray]);73 74 // Check string for issues while editing75 $(input).on('input focus', input, () =>76 {77 // Append any invalid issues to string when editing78 invalidString = "";79 invalidString += this.lengthCheck(input, minLength, maxLength);80 invalidString += this.illegalCharCheck(input, illegalCharArray);81 this.showWarning(input, inputId, invalidString);82 });83 // Enable submit again on an input change84 $(input).on('input', input, () =>85 {86 this.submitDisabled(false, this.submitButtonText);87 });88 // Check string for issues after editing89 $(input).on('focusout', input, () =>90 {91 invalidString += this.necessaryCharCheck(input, necessaryCharArray);92 invalidString += this.emailCheck(input);93 this.showWarning(input, inputId, invalidString);94 // Remove green border95 this.removeValid(input);96 });97 return invalidString;98 }99 /*100 Used for registering passwords. Almost the same as the requireText() function. This function requires at least101 one special character and number in the password. It is also possible to assign a confirmation input using passConfirmId.102 */103 registerPassword(inputId, minLength, maxLength, illegalCharArray, necessaryCharArray, passConfirmId)104 {105 let input = $("#" + inputId);106 let passConfirm = $("#" + passConfirmId);107 let invalidString = "";108 let invalidCheckString = "";109 // Create requried *110 this.createAsterisk(input);111 this.createAsterisk(passConfirm);112 // Add this input to the input log, for easy check alls113 this.inputLog.push(["registerPassword", inputId, minLength, maxLength, illegalCharArray, necessaryCharArray, passConfirmId]);114 115 // On editing main password116 $(input).on('input focus', input, () =>117 {118 // Append any invalid issues to string when editing119 invalidString = "";120 invalidString += this.lengthCheck(input, minLength, maxLength);121 invalidString += this.illegalCharCheck(input, illegalCharArray);122 this.showWarning(input, inputId, invalidString);123 // Check if passwords match124 invalidCheckString = "";125 invalidCheckString += this.passwordMatchCheck(input, passConfirm);126 this.showWarning(passConfirm, passConfirmId, invalidCheckString);127 });128 // Enable submit again on an input change129 $(input).on('input', input, () =>130 {131 this.submitDisabled(false, this.submitButtonText);132 });133 // Check string for issues after editing134 $(input).on('focusout', input, () =>135 {136 invalidString += this.necessaryCharCheck(input, necessaryCharArray);137 invalidString += this.capitalCheck(input);138 invalidString += this.numberCheck(input);139 invalidString += this.specialCharCheck(input);140 this.showWarning(input, inputId, invalidString);141 // Remove green border142 this.removeValid(input);143 this.removeValid(passConfirm);144 });145 // CONFIRM PASSWORD //146 $(passConfirm).on('input focus', passConfirm, () =>147 {148 invalidCheckString = "";149 invalidCheckString += this.passwordMatchCheck(input, passConfirm);150 this.showWarning(passConfirm, passConfirmId, invalidCheckString);151 });152 // Enable submit again on an input change153 $(passConfirm).on('input', input, () =>154 {155 this.submitDisabled(false, this.submitButtonText);156 });157 $(passConfirm).on('focusout', passConfirm, () =>158 {159 this.removeValid(passConfirm);160 });161 return invalidString;162 }163 ////////////164 // Checks //165 ////////////166 /*167 Checks return nothing if there are no issues.168 If there is a validation issue, a string is returned that explains the issue.169 The main functions call these depending on their parameters.170 Returns: String containing the error or blank171 */172 // Checks if too long or short173 lengthCheck(input, minLength, maxLength)174 {175 if (input.val().length <= minLength)176 {177 return "Debe contener mas de " + minLength + " caracteres. ";178 }179 else if (input.val().length >= maxLength)180 {181 return "No debe contener menos de " + maxLength + " caracteres. ";182 }183 else184 {185 return "";186 }187 }188 // Checks if contains unwanted text189 illegalCharCheck(input, illegalCharArray)190 {191 // Reset loop stringe192 let illegalsUsed = "";193 // loop through each illegal item to check for194 $(illegalCharArray).each(function()195 {196 if (input.val().indexOf(this) >= 0)197 {198 // Append illegal strings to var199 // check if char is a space200 if (!this.trim().length == 0)201 {202 illegalsUsed += " " + this; 203 }204 else205 {206 illegalsUsed += " espacios"207 }208 }209 });210 // Create output based on result of illegals concatination211 if (illegalsUsed === "")212 {213 return "";214 }215 else216 {217 return "No se pueden usar:" + illegalsUsed + ". ";218 }219 }220 // Check if doesnt contain needed text221 necessaryCharCheck(input, necessaryCharArray)222 {223 let notUsed = "";224 // loop through each illegal item to check for225 $(necessaryCharArray).each(function()226 {227 if (!(input.val().indexOf(this) >= 0))228 {229 notUsed += " " + this;230 }231 });232 // Create output based on result of illegals concatination233 if (notUsed === "")234 {235 return "";236 }237 else238 {239 return "Debe contener:" + notUsed + ". ";240 }241 }242 // Ensure that input has at least one number243 numberCheck(input)244 {245 if (!input.val().match(/\d/))246 {247 return "Debe contener un número. ";248 }249 else250 {251 return "";252 }253 }254 // Ensure there is at least one special character255 specialCharCheck(input)256 {257 if (!input.val().match(/\W|_/g))258 {259 return "Debe contener un caracter especial. ";260 }261 else262 {263 return "";264 }265 }266 // Regex for at least one capital267 capitalCheck(input)268 {269 if (input.val().match(/[A-Z]+/))270 {271 return "";272 }273 else274 {275 return "Debe contener mayúsculas. ";276 }277 }278 // Check if passwords match279 passwordMatchCheck(input, passConfirm)280 {281 if (input.val() === passConfirm.val())282 {283 return "";284 }285 else286 {287 return "Las contraseñas no coinciden. ";288 }289 }290 // Use regex to require an email291 emailCheck(input)292 {293 if (input.val().match(/^[^\s@]+@[^\s@]+\.[^\s@]+$/))294 {295 return "";296 }297 else298 {299 return "No es un e-mail válido";300 }301 }302 ////////////////303 // Check Alls //304 ////////////////305 /*306 These functions deal with form submission, checking all inputs before allowing submission307 */308 // Enable/Disable the submit button, and change its value309 submitDisabled(trueFalse, value)310 {311 $(this.submitButton).prop('disabled', trueFalse);312 $(this.submitButton).val(value);313 }314 checkAll()315 {316 $(this.form).submit( (e) =>317 {318 // Loop through every input added to object319 $(this.inputLog).each( (i) =>320 {321 // Reset loop variables322 let invalidString = "";323 let invalidCheckString = "";324 let thisLog = this.inputLog[i];325 // Make block scope elements to help understand which elements in the array are which326 let inputId = thisLog[1];327 let input = $("#" + inputId);328 let minLength = thisLog[2];329 let maxLength = thisLog[3];330 let illegalCharArray = thisLog[4];331 let necessaryCharArray = thisLog[5];332 if (thisLog[0] === "registerPassword")333 {334 var passConfirmId = thisLog[6];335 var passConfirm = $("#" + passConfirmId);336 }337 // Check for issues338 invalidString = "";339 invalidString += this.lengthCheck(input, minLength, maxLength);340 invalidString += this.illegalCharCheck(input, illegalCharArray);341 invalidString += this.necessaryCharCheck(input, necessaryCharArray);342 if (thisLog[0] === "requireEmail")343 {344 invalidString += this.emailCheck(input);345 }346 if (thisLog[0] === "registerPassword")347 {348 invalidString += this.capitalCheck(input);349 invalidString += this.numberCheck(input);350 invalidString += this.specialCharCheck(input);351 invalidCheckString += this.passwordMatchCheck(input, passConfirm);352 }353 // Display issues354 if (invalidString)355 {356 this.showWarning(input, inputId, invalidString);357 this.submitDisabled(true, "Error, por favor revise su formulario");358 // Stop submission359 e.preventDefault();360 }361 if (invalidCheckString)362 {363 this.showWarning(passConfirm, passConfirmId, invalidCheckString);364 this.submitDisabled(true, "Error, por favor revise su formulario");365 // Stop submission366 e.preventDefault();367 }368 });369 });370 }371 ////////////////////372 // Class Updating //373 ////////////////////374 /*375 Simplifies redundant class code into a few functions376 */377 // Perform restrictions depending on the input378 showWarning(input, inputId, invalidString)379 {380 // Provide proper styling and feedback381 if (invalidString)382 {383 this.generateFeedback(input, inputId, "invalid-feedback", invalidString);384 this.makeInvalid(input);385 }386 else387 {388 this.generateFeedback(input, inputId, "", "");389 this.makeValid(input);390 }391 }392 // Adds a valid class to element and removes invalid393 makeValid(element)394 {395 if (!element.hasClass(this.validC))396 {397 element.addClass(this.validC);398 }399 // Remove invalid class if it exists400 if (element.hasClass(this.invalidC))401 {402 element.removeClass(this.invalidC);403 }404 }405 // Adds a valid class to element and removes invalid406 removeValid(element)407 {408 // Remove invalid class if it exists409 if (element.hasClass(this.validC))410 {411 element.removeClass(this.validC);412 }413 }414 // adds invalid class to element and removes valid class415 makeInvalid(element)416 {417 if (!element.hasClass(this.invalidC))418 {419 element.addClass(this.invalidC);420 }421 // Remove valid class422 if (element.hasClass(this.validC))423 {424 element.removeClass(this.validC);425 }426 }427 /////////////////////428 // Text Generation //429 /////////////////////430 /*431 Visual output such as errors or *432 */433 // Create required asterisk after text434 createAsterisk(input)435 {436 //pinta un * delante del input ( no me interesa )437 //$("<span class='text-danger'>*</span>").insertBefore(input)438 }439 // Creates responsive tiny text below inputs to inform user of issues440 generateFeedback(input, inputId, validityClass, prompt)441 {442 // Delete feedback if it already exists to make room for new content443 $('#' + inputId + '-feedback').remove();444 445 // Create feedback element if it does not exist446 $('<div id="' + inputId + '-feedback" class="' + validityClass + '">' + prompt + '</div>').insertAfter(input);447 }...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1var wptools = require('wptools');2var wiki = wptools.page('Pune');3wiki.get(function(err, resp) {4 if (err) {5 console.log(err);6 } else {7 console.log(wiki.invalidString());8 }9});

Full Screen

Using AI Code Generation

copy

Full Screen

1var wptools = require('wptools');2var wiki = new wptools('invalidString');3wiki.get(function(err, data) {4 if (err) {5 console.log('Error: ' + err);6 } else {7 console.log('Success: ' + data);8 }9});10#### wptools([query])11#### wptools.get([callback])12#### wptools.get([options], [callback])13#### wptools.get([options], [callback])14#### wptools.get([options], [callback])15#### wptools.get([options], [callback])16#### wptools.get([options], [callback])17#### wptools.get([options], [callback])18#### wptools.get([options], [callback])19#### wptools.get([options], [callback])20#### wptools.get([options], [callback])21#### wptools.get([options], [callback])22#### wptools.get([options], [callback])23#### wptools.get([options], [callback])24#### wptools.get([options], [callback])25#### wptools.get([options], [callback])26If you would like to contribute to this project, please review the [CONTRIBUTING.md](

Full Screen

Using AI Code Generation

copy

Full Screen

1var mystr = "this is a test string";2var invalidString = wptextpattern.invalidString(mystr);3console.log(invalidString);4var invalidString = wptextpattern.invalidString("this is a test string");5console.log(invalidString);6var invalidString = wptextpattern.invalidString();7console.log(invalidString);8var invalidString = wptextpattern.invalidString(123);9console.log(invalidString);10var invalidString = wptextpattern.invalidString(123.45);11console.log(invalidString);12var invalidString = wptextpattern.invalidString(true);13console.log(invalidString);14var invalidString = wptextpattern.invalidString(false);15console.log(invalidString);16var invalidString = wptextpattern.invalidString(null);17console.log(invalidString);18var invalidString = wptextpattern.invalidString(undefined);19console.log(invalidString);20var invalidString = wptextpattern.invalidString({});21console.log(invalidString);22var invalidString = wptextpattern.invalidString([]);23console.log(invalidString);24var invalidString = wptextpattern.invalidString(function () {});25console.log(invalidString);26var invalidString = wptextpattern.invalidString(/test/);27console.log(invalidString);28var invalidString = wptextpattern.invalidString(new Date());29console.log(invalidString);30var invalidString = wptextpattern.invalidString(new Error());31console.log(invalidString);

Full Screen

Using AI Code Generation

copy

Full Screen

1var wptools = require('wptools');2var testString = 'test';3var testString2 = 'test2';4wptools.invalidString(testString, function(err, response){5 if(err){6 console.log('error: ' + err);7 }8 else{9 console.log('response: ' + response);10 }11});12wptools.invalidString(testString2, function(err, response){13 if(err){14 console.log('error: ' + err);15 }16 else{17 console.log('response: ' + response);18 }19});

Full Screen

Using AI Code Generation

copy

Full Screen

1var wptools = require('wptools');2wptools.invalidString("test").then(function(result) {3 console.log(result);4});5var wptools = require('wptools');6wptools.page("test").then(function(result) {7 console.log(result);8});9var wptools = require('wptools');10wptools.query("test").then(function(result) {11 console.log(result);12});13var wptools = require('wptools');14wptools.queryProp("test").then(function(result) {15 console.log(result);16});17var wptools = require('wptools');18wptools.raw("test").then(function(result) {19 console.log(result);20});

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run wpt automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful