Hi,
I want to create an input field that accepts only uppercase characters. If a user tries to input a lowercase character, the input field should prevent it from being typed.Thanks and regards
Ved
Hi Vednarayan
Write this script within the 'onready' function of the screen.
Refer to this link for the demo DemoLink
document.getElementById($parameters.Inputboxid).addEventListener("keydown", function(event) { if (event.key === event.key.toLowerCase()) { event.preventDefault(); }});
Thanks,
Jothikarthika
Hi Vednarayan,
One of the possible solution is to register the input widget keypress event handler with the following definition to restrict lowercase characters.
JS Snippet: InputJSTask
document.getElementById($parameters.InputWidget_Id).addEventListener('keypress', function(event){ // Get the character code of the key that was pressed let charCode = event.charCode; // Check if the character is a lowercase letter if (charCode >= 97 && charCode <= 122) { event.preventDefault(); } });
(source: Google search)
I hope this helps!
Kind regards,
Benjith Sam
if (event.key >= 'a' && event.key <= 'z') {
event.preventDefault();
let uppercaseKey = event.key.toUpperCase();
inputField.value += uppercaseKey;
}
The keypress event listener prevents lowercase characters from being typed and replaces them with their uppercase counterparts immediately.
Try to use this regex code in JS.
document.addEventListener('DOMContentLoaded', function() {
var inputField = document.getElementById($parameters.InputField);
inputField.addEventListener('input', function(event) {
var value = inputField.value;
var newValue = value.replace(/[a-z]/g, ''); // Remove lowercase letters
if (newValue !== value) {
inputField.value = newValue;
});
Gokulprasanth M
Hey @Vednarayan
*If you want to convert whatever user entered into upper case then use buildin function
ToUpper("First string") = "FIRST STRING"
*If want to prevent entering lower case character in input then try solution suggested by @Benjith Sam
Hi @Vednarayan, you try my component Restrict Characters, here is the demo.
ThanksGitansh Anand