LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
LinkBack Search this Thread
Old 11-06-2005, 02:31 PM   #1
ALInux
Member
 
Registered: Nov 2003
Location: Lebanon
Distribution: RHEL 5/CentOS 5/Debian Lenny/(K)Ubuntu Is Dead/Mandriva 10.1
Posts: 660
Blog Entries: 6

Rep: Reputation: 31
regular expressions in php


Hi I need an regular expression that I can use with preg_match() ...I want it to return true if argument is an alphanumeric and false otherwise.

What is the purpose of the statement beneath?
$x = preg_match ("/[A-z]+[0-9]+/", $password)
 
Old 11-06-2005, 02:41 PM   #2
keefaz
Senior Member
 
Registered: Mar 2004
Distribution: Slackware
Posts: 4,282

Rep: Reputation: 61
Try :
PHP Code:
$x preg_match("/^[A-z-0-9]+$/"$password); 
^ : begin of text
[A-z-0-9] : any letter from A to z, any number from 0 to 9
+ : one or more time
$ : end of text
 
Old 11-07-2005, 02:21 AM   #3
ALInux
Member
 
Registered: Nov 2003
Location: Lebanon
Distribution: RHEL 5/CentOS 5/Debian Lenny/(K)Ubuntu Is Dead/Mandriva 10.1
Posts: 660
Blog Entries: 6

Original Poster
Rep: Reputation: 31
Does the "+ : one or more time" guarantee that there is at least one number and one letter ??
 
Old 11-07-2005, 05:28 AM   #4
keefaz
Senior Member
 
Registered: Mar 2004
Distribution: Slackware
Posts: 4,282

Rep: Reputation: 61
That guarantees that there is at least one number OR one letter

You could use strlen() if you want to test the password contain a minimal
number of character before the preg_match()
 
Old 11-07-2005, 11:48 AM   #5
ALInux
Member
 
Registered: Nov 2003
Location: Lebanon
Distribution: RHEL 5/CentOS 5/Debian Lenny/(K)Ubuntu Is Dead/Mandriva 10.1
Posts: 660
Blog Entries: 6

Original Poster
Rep: Reputation: 31
thank you for your continous support....I think Iam not explaining what I want in the right way.

I want at least one number AND at least one character.



Thanks again it is people like you who make this site so succesfull

Last edited by ALInux; 11-07-2005 at 11:53 AM.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Php and regular expressions logicdisaster Programming 9 06-26-2004 05:01 PM
Regular Expressions overbored Linux - Software 3 06-24-2004 02:34 PM
help with REGULAR EXPRESSIONS ner Linux - General 23 10-31-2003 11:09 PM
Regular expressions aromes Linux - General 1 10-15-2003 12:29 PM
regular expressions? alaios Linux - General 2 06-11-2003 03:51 PM


All times are GMT -5. The time now is 05:12 AM.

Main Menu
 
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: @linuxquestions
Open Source Consulting | Domain Registration