gaozhy
0.01D
V2EX  ›  问与答

正则表达式 只能输入数字、小数和字母 应该怎么写

  •  
  •   gaozhy · Jun 10, 2022 · 2144 views
    This topic created in 1607 days ago, the information mentioned may be changed or developed.
    满足规则:
    - 11.1
    - 11
    - "Abc"
    - "Abc11.0"
    - "Abc11.1d"

    不满足规则:
    - "Abc11.d" 11.d 不是数字
    9 replies  •  2022-06-10 21:37:11 +08:00
    ink19
    ink19
    Jun 10, 2022
    1
    11.也可以认为是数字吧
    gaozhy
    gaozhy
    OP
    Jun 10, 2022
    2
    @ink19 11. 不满足规则 需要是数字或者小数出现
    longbow0
    longbow0
    Jun 10, 2022
    3
    abc1.1.1abc 算不算?
    just1
    just1
    Jun 10, 2022
    4
    ^(\d+(\.\d+)?|[a-zA-Z]+)+$
    superychen
    superychen
    Jun 10, 2022
    5
    示例里带字母的情况下都加了双引号,双引号算不算在里面?
    darklights
    darklights
    Jun 10, 2022
    6
    @just1 思路跟你差不多,但是无法排除 1.11.1x
    superychen
    superychen
    Jun 10, 2022
    7
    试试这个

    ^\S[a-zA-Z]*(\d+(.\d+)?d?)?$
    just1
    just1
    Jun 10, 2022❤️1
    8
    @darklights ^((\d+(\.\d+)?(?!\d))|[a-zA-Z])+$
    数字末尾加个否定就行了
    gaozhy
    gaozhy
    OP
    Jun 10, 2022
    9
    @just1
    @superychen 谢谢各位老哥~
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   1468 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 30ms · UTC 22:03 · PVG 06:03 · LAX 14:03 · JFK 17:03
    ♥ Do have faith in what you're doing.