韩国和字母正则表达式返回虚假

时间:2015-08-27 01:08:23

标签: javascript regex forms

我在验证网站的表单输入时遇到了问题。我正在寻找接受名字字段的英文字符和韩文字符。我输入韩文字符没有问题,但是当我添加韩语正则表达式时,函数返回false而没有返回true。

var recommend_coffee_your_name_field = $('#coffee_recommend_your_name_field');

recommend_coffee_your_name_field.keyup(function(e) {
  var $th = $(this);
  $th.val( $th.val().replace(/[^a-zA-Z0-9\u{3130}-\u{318F}\u{AC00}-\u{D7AF}]/g, function(str) { 
    alert('You typed " ' + str + ' ".\n\nPlease use only letters and numbers.'); return ''; 
  } ) );

  if(e.keyCode !== 8 || e.keyCode !== 9 ) {             
    var recommend_coffee_your_name_field_length = recommend_coffee_your_name_field.val().length;
    //console.log("Your Name Field Length: " + your_name_field_length);

    if( recommend_coffee_your_name_field_length > 0 ){
      //recommend_coffee_your_name_field.removeClass("error").addClass("success");
      recommend_coffee_shop_your_name_value = true;
    }
    else{
      //recommend_coffee_your_name_field.removeClass("success").addClass("error");
      recommend_coffee_shop_your_name_value = false;
    }
    if (!recommend_coffee_shop_your_name_value) {
      alert("The name field is missing");
      e.preventDefault();
    } 
});

0 个答案:

没有答案