javascript - Can I set input language of a textbox or textarea? -
i'm building urdu language website which, let's say, similar blogging website. want enforce users make posts in no language other urdu.
one solution have in mind manually capture each key pressed in javascript , display alternate in urdu in textbox. this:
'a'-> 'ا' , 'b' -> 'ب'
i dont find efficient solution @ , know if there sort of plug-in use sets input language of textbox? or if must write code of own, have solution other 1 above?
to me possible using regex : of the wikipedia page of urdu alphabet can unicode range of urdu language : [\u0600-\u06ff] , [\u0750-\u077f] , [\ufb50-\ufdff] , [\ufe70-\ufeff]
you can try : bind jquery event when key pressed, key string, test if urdu, add char if is, nothing if isn't:
$('#yourtextarea').bind('keydown',function(evt){ evt.stoppropagation(); // stop propagating key pressed var textareaval = $('#yourtextarea').val() var urduregex = /[\u0600-\u06ff]|[\u0750-\u077f]|[\ufb50-\ufdff]|[\ufe70-\ufeff]/; chartotest = string.fromcharcode(evt.keycode); // char related key pressed if(urduregex.test(chartotest)) // if urdu {$('#yourtextarea').val(textareaval + chartotest )} // add char textarea else {return;} // nothing }
[not tested] though sure can work around that...
Comments
Post a Comment