Hi nedash,
Refer below sample.
If you want to change persian number to english on key press then use the below code.
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
<script type="text/javascript">
$(function () {
$('[id*=TxtTsabet]').keyup(function (e) {
var ctrlKey = 67, vKey = 86;
if (e.keyCode != ctrlKey && e.keyCode != vKey) {
$('[id*=TxtTsabet]').val(persianToEnglish($(this).val()));
}
});
});
function persianToEnglish(input) {
var inputstring = input;
var persian = ["۰", "۱", "۲", "۳", "۴", "۵", "۶", "۷", "۸", "۹"]
var english = ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9"]
for (var i = 0; i < 10; i++) {
inputstring = inputstring.toString().replace(persian[i], english[i]);
}
return inputstring;
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<input name="TxtTsabet" type="text" id="TxtTsabet" />
</div>
</form>
</body>
</html>
Demo
If you want to insert only english number based on your textbox value(persian) to database then use the below method.
private string[] persion = { "۰", "۱", "۲", "۳", "۴", "۵", "۶", "۷", "۸", "۹" };
private string[] english = { "0", "1", "2", "3", "4", "5", "6", "7", "8", "9" };
public string PersianToEnglish(string strNum)
{
string chash = strNum;
for (int i = 0; i < 10; i++)
chash = chash.Replace(persion[i], english[i]);
return chash;
}
And call in your page like below.
_cmd.Parameters.AddWithValue("@Malekphone", PersianToEnglish(TxtTsabet.Text));