I am trying to remove the word noZero form here when a condition is met in JavaScript. I'm not sure how to access this and remove what I need. I know I wanna do something like how you would remove or add a CSS class but this is my first time running into a custom validation type like this. Does any one have some suggestions?
I have used this to get the information inside data-validate-rules. document.getElementById("monthlyIncome").dataset.validateRules.split(",").map((rule) => rule.trim());
I not sure how I would go about adding something or removing something.
<input class="validate" data-validate-rules="required,noZero" id="monthlyIncome" type="text" name="monthlyIncome" maxlength="11" value="">
CodePudding user response:
You could do that :
var element = document.querySelector("#monthlyIncome");
element.setAttribute("data-validate-rules", element.getAttribute("data-validate-rules").replace(new RegExp(",?noZero"), ""));