I have an input that I want to create custom validations, I need to get its value and validate the first character of the input, what would be the best way to do this?
I have an input that I want to create custom validations, I need to get its value and validate the first character of the input, what would be the best way to do this?
Take the value of the input and use the charAt function with the position of the character in case 0.
var valor = $('#id_input').val();
alert(valor.charAt(0));
Version without jQuery.
Because you do not need jQuery for this.
const input = document.getElementById('input1');
const primeiro = input.value[0];
console.log(primeiro);
<input id="input1" type="text" value="um monte de texto" />