I want to limit the value a user can send to an API, for example, Users can only send the value of 30
By using minlength="" maxlength="" I can limit the number of chars typed but I cannot, for example, stop the user from entering 9999999 and overloading the results or not getting a result.
<input type="number" id="passlen" class="pass-len-box" min="4" max="20" placeholder="Enter password length"
required>
Using type="number" will stop user inputting Text but it will still pass lower values (min="5" max="20") I can still pass 1,2,3,4, and 1234
<input id="passlen" class="pass-len-box" minlength="3" maxlength="20" placeholder="Enter password length"
required>
<button class="generatorPass" id="genratorPass">Generate</button>
<p id="dispPassword"></p>
document.querySelector("#genratorPass").addEventListener("click", () => {
const user_input_text = document.querySelector("#passlen");
request(
user_input_text
);
});
const passworldEl = document.getElementById("dispPassword");
request = (
user_input_text,
) => {
let url = `https://passwordwolf.com/api/?length=${user_input_text.value}&repeat=1`;
fetch(url)
.then((response) => response.json())
.then((responseJson) => {
for (let { password } of responseJson) {
const apipass = document.createElement("p");
apipass.innerText = password;
document.querySelector("#dispPassword").innerHTML = password;
console.log(password);
}
});
};