需要使用jquery输入正则表达式

时间:2016-06-12 17:39:30

标签: jquery regex

我需要正则表达式,以便只允许这些字符输入:

A B C D E F G H I J K L M N O P Q R S T U V W X Y Z 0 1 2 3 4 5 6 7 8 9& ,。 - /()@ * +! ? “':;

如果我可以在这段代码中通过jQuery实现它,那将是很好的:

$("#firstText").keyup(function () {
  var value = $(this).val().toUpperCase();
  $(".zetin16").text(value);
}).keyup();

1 个答案:

答案 0 :(得分:0)

描述

^[A-Z0-9&,.\/()@*+!?“‘:;-]+$

Regular expression visualization

此正则表达式将执行以下操作:

  • 仅允许这些字符ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789&,.–/()@*+!?“‘:;

实施例

现场演示

https://regex101.com/r/bO2zN4/1

解释

^ assert position at start of a line
[A-Z0-9&,.\/()@*+!?“‘:;-]+ match a single character present in the list below
    A-Z a single character in the range between A and Z (case sensitive)
    0-9 a single character in the range between 0 and 9
    &,. a single character in the list &,. literally (case sensitive)
    \/ matches the character / literally
    ()@*+!?“‘:;- a single character in the list ()@*+!?“‘:;- literally
Quantifier: + Between one and unlimited times, as many times as possible, giving back as needed [greedy]
$ assert position at end of a line