サインアップ時にユーザー名をクリーンアップするためにJavaScriptコードを使用します。文字が許可されていない場合は、ダッシュに置き換えられます。
私の問題は、ユーザーがテキストの途中に文字を追加したい場合、カーソルが入力の最後に自動的に置かれることです。
ここでテストできます:http://jsfiddle.net/tZv5X/
HTML:
Username : <input type="text" id="username" />
JS:
// Clean username
function clean_username(s)
{
var temp = s.replace(/[àâä@]/gi,"a");
temp = temp.replace(/[éèêë]/gi,"e");
temp = temp.replace(/[îï]/gi,"i");
temp = temp.replace(/[ôö]/gi,"o");
temp = temp.replace(/[ùûü]/gi,"u");
temp = temp.replace(/[ç]/gi,"c");
temp = temp.replace(/[. _,;?!&+'"()]/gi,"-");
return temp;
}
var current_value;
$("#username").keyup(function(e)
{
if($(this).val() != current_value)
{
$(this).val(clean_username($(this).val()));
current_value = $(this).val();
}
});
何か案が ?
ありがとう