here is my code for a textareainput to accept only characters not numbers.
var harfInput1 = document.getElementById('graduated_university_country'); harfInput1.addEventListener("keyup",function(){ if (harfInput1.value.match(/[^a-zA-Z' ']/g)){ harfInput1.value = this.value.replace(/[^a-zA-Z]/g,''); } })
Problem is i cannot accept Turkish characters like this. I tried to add code below but it did not work.
var harfInput1 = document.getElementById('graduated_university_country'); harfInput1.addEventListener("keyup",function(){ if (harfInput1.value.match(/[^a-zA-Z' '][^wığüşöçĞÜŞÖÇİ]/g)){ harfInput1.value = this.value.replace(/[^a-zA-Z][^wığüşöçĞÜŞÖÇİ]/g,''); } })
Any suggestions?
Advertisement
Answer
You can use below code snippet to catch all alpha letters including Turkish letters with Javascript using Regular expressions.
var harfInput1 = document.getElementById('graduated_university_country'); harfInput1.addEventListener("keyup",function(){ if (harfInput1.value.match(/[^a-zA-Z' 'wığüşöçĞÜŞÖÇİ]/g)){ harfInput1.value = this.value.replace(/[^a-zA-ZwığüşöçĞÜŞÖÇİ]/g,''); } })
<textarea name="" id="graduated_university_country" cols="" rows=""></textarea>