使用正则表达式

Work with regular expressions

我正在使用 codeignter 框架,我想使用 bootstrap 验证字段 validator.How 我制作了一个常规的 expression.I am usign bootstrap 验证器。

示例 1:I 想要验证年龄字段,其中只允许数字 value.But 我输入。(点或小数)这也被认为是错误的。 我想要这样的年龄:

Success Scenario Examples:
16  ,

  20 ,  50  , 60 
    Wrong Scenario Examples:
    16.5   ,  20.5 ,   25.5

    I want this will not consist of decimal point.
Here is my code:
professional_age: {
                validators: {
                    lessThan: {
                        value: 100,
                        inclusive: true,
                        message: 'The ages has to be less than or equal to 100'
                    },
                    greaterThan: {
                        value: 15,
                        inclusive: true,
                        message: 'The ages has to be greater than or equals to 15'
                    }
                }
            }

示例 2: 我想要电子邮件正则表达式:

These are success scenario:
zainqureshi55@gmail.com

These are wrong scenario:
zain@gmail45.com
zain@45gmail.com
zain@gmail.
Please how we make regular expression:

示例 3:I 想要一个常规的 expression.In 字母表和数值 allowed.One 字母表是必须的。

This is success scenario:
123456d
123d5456
a25d852e
This is wrong scenario:
11233658

正则可以这样:

^(?=.*[a-zA-Z])([a-zA-Z\d]+)$

Positive Lookahead 测试至少存在一个字符

demo and some explanation

您正在寻找的是积极的展望。这将检查字符串是否包含某个正则表达式。

^(?=.*[a-zA-Z])[a-zA-Z\d]*$

解释:

^                 // Start of the string
(?=.*[a-zA-Z])    // Does it have a character?
[a-zA-Z\d]*       // The rest should be alphanumeric
$                 // End of the string

可以在 https://regexr.com/3hrgl

找到更长的解释和示例