【问题标题】:Need regex for input with jquery需要正则表达式用于 jquery 的输入
【发布时间】:2016-10-13 03:10:09
【问题描述】:

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

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();

【问题讨论】:

  • 您是否至少最小化努力自己解决问题?
  • 'Regix' 给出了答案@nicael
  • 这不是问题……这是对代码的需求。 Stackoverflow 不是代码编写服务。请阅读How to Ask 并向我们展示您的一些未按预期进行的研究工作
  • 什么?我什至没有任何编写正则表达式的经验。难吗?
  • 是的......正则表达式很复杂......虽然搜索互联网不是。在这里提出问题不应该是你的研究起点。你应该先这样做

标签: jquery regex


【解决方案1】:

说明

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

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

  • 将只允许这些字符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

【讨论】:

    猜你喜欢
    • 2023-01-24
    • 1970-01-01
    • 1970-01-01
    • 2014-06-03
    • 2016-01-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多