如何使用jquery只允许表单文本字段中的阿拉伯字符
我试过这个,但箭头不允许从最后一行回来
如果有的话,请告诉我或编辑我的代码或提供任何新代码
Character Filtering Arabic Only (onchange):
Eloims.. 7
从Unicode 6.1开始,阿拉伯语脚本包含在以下块中(来自 阿拉伯语的正则表达式)
Arabic (0600—06FF, 225 characters) Arabic Supplement (0750—077F, 48 characters) Arabic Extended-A (08A0—08FF, 39 characters) Arabic Presentation Forms-A (FB50—FDFF, 608 characters) Arabic Presentation Forms-B (FE70—FEFF, 140 characters) Rumi Numeral Symbols (10E60—10E7F, 31 characters) Arabic Mathematical Alphabetic Symbols (1EE00—1EEFF, 143 characters)
对您的文本字段使用正则表达式验证,使用您正在使用的任何框架.
var isArabic = /^([\u0600-\u06ff]|[\u0750-\u077f]|[\ufb50-\ufbc1]|[\ufbd3-\ufd3f]|[\ufd50-\ufd8f]|[\ufd92-\ufdc7]|[\ufe70-\ufefc]|[\ufdf0-\ufdfd])*$/g; // Solution 1: This will add an error class when the input does not match $("#txtArabic1").change(function() { $(this).toggleClass("has-error", !isArabic.test(this.value)); }) // Solution 2: This will not let the user type chars that are not arabic // but seem to fail on my browser... I don't quite get how does // javascript splits the string. $("#txtArabic2").bind('keyup', function(e) { var filterFn = isArabic.test.bind(isArabic), newValue = this.value.split('').filter(filterFn).join(''); if (this.value != newValue) this.value = newValue; });
这是一个jsfiddle
从Unicode 6.1开始,阿拉伯语脚本包含在以下块中(来自 阿拉伯语的正则表达式)
Arabic (0600—06FF, 225 characters) Arabic Supplement (0750—077F, 48 characters) Arabic Extended-A (08A0—08FF, 39 characters) Arabic Presentation Forms-A (FB50—FDFF, 608 characters) Arabic Presentation Forms-B (FE70—FEFF, 140 characters) Rumi Numeral Symbols (10E60—10E7F, 31 characters) Arabic Mathematical Alphabetic Symbols (1EE00—1EEFF, 143 characters)
对您的文本字段使用正则表达式验证,使用您正在使用的任何框架.
var isArabic = /^([\u0600-\u06ff]|[\u0750-\u077f]|[\ufb50-\ufbc1]|[\ufbd3-\ufd3f]|[\ufd50-\ufd8f]|[\ufd92-\ufdc7]|[\ufe70-\ufefc]|[\ufdf0-\ufdfd])*$/g; // Solution 1: This will add an error class when the input does not match $("#txtArabic1").change(function() { $(this).toggleClass("has-error", !isArabic.test(this.value)); }) // Solution 2: This will not let the user type chars that are not arabic // but seem to fail on my browser... I don't quite get how does // javascript splits the string. $("#txtArabic2").bind('keyup', function(e) { var filterFn = isArabic.test.bind(isArabic), newValue = this.value.split('').filter(filterFn).join(''); if (this.value != newValue) this.value = newValue; });
这是一个jsfiddle