Reputation: 2084
I'm trying to check if an input text has only Arabic text in it's value.
This is what I tried :
var test = function() {
var isArabic = /^([\u0600-\u06ff]|[\u0750-\u077f]|[\ufb50-\ufbc1]|[\ufbd3-\ufd3f]|[\ufd50-\ufd8f]|[\ufd92-\ufdc7]|[\ufe70-\ufefc]|[\ufdf0-\ufdfd]|[ ])*$/g;
if(isArabic.test($.trim($('#arabicFirstname').val()))){
console.log('is arabic');
}else{
console.log('not arabic');
}
}
But I'm always getting not arabic
even though I only type Arabic characters.
How can I solve this ?
Upvotes: 1
Views: 1998
Reputation: 2195
You have missed the jQuery selector like .arabicFirstname
or #arabicFirstname
in the following:
arabicFirstname is Class Name:
if(isArabic.test($('.arabicFirstname').val())){
console.log('is arabic');
}else{
console.log('not arabic');
}
arabicFirstname is ID:
if(isArabic.test($('#arabicFirstname').val())){
console.log('is arabic');
}else{
console.log('not arabic');
}
Upvotes: 2