简体   繁体   中英

Display error message when blocked words entered in text boxes on button click in MVC 3

Requirement:

Need to display an error message on button click when blocked words are entered in 3 available text boxes using JavaScript function. Given:
1) 100 blocked words are already provided, so planning to save it in JSON file or please recommend what approach is good?
2) The onclick function already present. Need to add logic to above requirement 3) Need to use plain JavaScript.

Have done the same thing in Angular JS using $http. But not able to move ahead for plain JavaScript.

Put the blocked words into an array, then iterate through each word, checking the inputting word against the blocked list - if there's a match, throw an error.

the click function would be something like:

yourArr.forEach((val) => {
  if (enteredWord === val) {
    //throw error
  } else {
    //do whatever you want
   }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM