Hello everyone,
I want to write a regular expression for all the expressions that contains at least 1 digit and at least one letter can anyone help me and tell me how to do that...
thanx in advance
creating regular expression
Started by mutaz, Jul 14 2009 03:29 AM
10 replies to this topic
#1
Posted 14 July 2009 - 03:29 AM
|
|
|
#2
Posted 14 July 2009 - 04:34 AM
"/([A-Za-z0-9]+)/" is for whatever combination of letters and numbers with demand of at least one. the within [] specifies what characters are allowed, the + means one or more.
__________________________________________
I study Information Systems at Karlstad University when I'm not on CodeCall
I study Information Systems at Karlstad University when I'm not on CodeCall
#3
Posted 14 July 2009 - 06:33 AM
but in this case (/([A-Za-z0-9]+)/) can i write any special character
in fact i want to be able to write any kind of characters but i want to force him to write at least one digit and one letter
in fact i want to be able to write any kind of characters but i want to force him to write at least one digit and one letter
#4
Posted 14 July 2009 - 06:35 AM
ah, then you go with "/(.+)/" as . (dot) is any char.
__________________________________________
I study Information Systems at Karlstad University when I'm not on CodeCall
I study Information Systems at Karlstad University when I'm not on CodeCall
#5
Posted 14 July 2009 - 06:42 AM
If you want anything atleast one character you could also just test the string length
"/(.){1,}/"
1 or more.
if(strlen($var)>=1) {
//do stuff
}
I also think this will work:"/(.){1,}/"
1 or more.
#6
Posted 14 July 2009 - 06:49 AM
thank you for help, but i'm afraid that this is not what i was looking of because may be i couldn't explain what i need
i needed something like for example : /([0-9]+[a-zA-z]+[any character is allowed even digits and letters])/
and of course i'm not forcing to be the digit in the first place and the letter in the second.
hope that i could clarified my self
i needed something like for example : /([0-9]+[a-zA-z]+[any character is allowed even digits and letters])/
and of course i'm not forcing to be the digit in the first place and the letter in the second.
hope that i could clarified my self
#7
Posted 14 July 2009 - 07:06 AM
what is the allowed characters then?
__________________________________________
I study Information Systems at Karlstad University when I'm not on CodeCall
I study Information Systems at Karlstad University when I'm not on CodeCall
#8
Posted 14 July 2009 - 07:12 AM
let me give you an example for accepted combination and not accepted combination
accepted combination like :
123db8$$#@ (contains letters and digits)
12345f6#$# (contains letters and digits)
988888m888 (contains letters and digits)
lkasdfasd6fkjlasdf&*#@ (contains letters and digits)
not accepted combination like :
adsfgtre#$%@ not accepted because doesn't contain any digit
123456675 not accepted because doesn't contain any letter
12547@!##@ not accepted because doesn't contain any letter
i hope that is clear enough...
accepted combination like :
123db8$$#@ (contains letters and digits)
12345f6#$# (contains letters and digits)
988888m888 (contains letters and digits)
lkasdfasd6fkjlasdf&*#@ (contains letters and digits)
not accepted combination like :
adsfgtre#$%@ not accepted because doesn't contain any digit
123456675 not accepted because doesn't contain any letter
12547@!##@ not accepted because doesn't contain any letter
i hope that is clear enough...
#9
Posted 14 July 2009 - 07:32 AM
Ah, that is a different thing :-) that is not within my knowledge unfortunately. I hope John or someone else here with good regexp knowledge can help you there.
__________________________________________
I study Information Systems at Karlstad University when I'm not on CodeCall
I study Information Systems at Karlstad University when I'm not on CodeCall
#10
Posted 14 July 2009 - 07:34 AM
The easiest way would be to require two matches, one for [0-9], the other for [a-zA-Z]. Otherwise you'd need something like:
(.*[0-9].*[a-zA-Z].*)|(.*[a-zA-Z].*[0-9].*)
(.*[0-9].*[a-zA-Z].*)|(.*[a-zA-Z].*[0-9].*)
#11
Posted 14 July 2009 - 01:02 PM
There is prolly an easier way to do it, but I was thinking along the lines of Panther. Within a loop you could test for [0-9], ding a var yes of no then swoop through another loop looking for [a-Z] and ding another var. Like I said, there's prolly an easier way but that is what my limited PHP knowledge brings to the table.
Edit: *ding* new page!
Edit: *ding* new page!


Sign In
Create Account

Back to top










