I am create small demo for write persian text enter in text box.i am search some links and try this code but this is not enter persian text enter only english text so can you please help me how can do that.and also want to validation on national id.
this is my html text box :
<input type="text" id="txtn" onkeypress="text(this)">
this is my js code :
function text(name)
{
var name = $(name).val();
just_persian(name);
}
function just_persian(str) {
var p = /^[\u0600-\u06FF\s]+$/;
if (!p.test(str)) {
alert("not format");
}
}
here i am enter any text always getting alert.
Try this code:
$("#txtn").on('change keyup paste keydown', function(e) {
if(just_persian(e.key) === false)
e.preventDefault();
});
function just_persian(str) {
var p = /^[\u0600-\u06FF\s]+$/;
if (!p.test(str)) {
return false
}
return true;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<input type="text" id="txtn">
I hope this work :)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With