473,407 Members | 2,629 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,407 software developers and data experts.

preg_match help

Help how can I force the variable to start with a character.

I dont want it to start with a number????

function alphanumeric($alphanumeric_field)
{
if(!preg_match("/[^a-zA-Z0-9]+$/",$alphanumeric_field))
return TRUE;
else
return FALSE;
}

any ideas much appreciated. As i am so frustrated with the preg_match
function!!
Dec 1 '06 #1
2 1920
I forgot to mention as well that it was allowing whitespace. Which i did not
want.

all i want is A-Z regardless of case. and Numbers. No other characters. And
start with a letter.


"David" <no****@nospanm.comwrote in message
news:q9**************@news-server.bigpond.net.au...
Help how can I force the variable to start with a character.

I dont want it to start with a number????

function alphanumeric($alphanumeric_field)
{
if(!preg_match("/[^a-zA-Z0-9]+$/",$alphanumeric_field))
return TRUE;
else
return FALSE;
}

any ideas much appreciated. As i am so frustrated with the preg_match
function!!

Dec 1 '06 #2

"David" <no****@nospanm.comwrote in message
news:km**************@news-server.bigpond.net.au...
>I forgot to mention as well that it was allowing whitespace. Which i did
not
want.

all i want is A-Z regardless of case. and Numbers. No other characters.
And
start with a letter.


"David" <no****@nospanm.comwrote in message
news:q9**************@news-server.bigpond.net.au...
>Help how can I force the variable to start with a character.

I dont want it to start with a number????

function alphanumeric($alphanumeric_field)
{
if(!preg_match("/[^a-zA-Z0-9]+$/",$alphanumeric_field))
return TRUE;
else
return FALSE;
}

any ideas much appreciated. As i am so frustrated with the preg_match
function!!
I haven't tested this, but you probably want something along these lines:

/^[A-Za-z][A-Za-z0-9]*$/

A '^' (carat) inside of '[]' means NOT (so, '[^A-Z]' means any single
character EXCEPT an upper-case letter). A '^' outside of '[]' means start of
line.

The above pattern, then, is looking for...

Start of line THEN a single alphabetic character (upper- or lower-case) THEN
zero or more alphabetic characters (upper- or lower-case) or decimal digits
THEN end of line (the '$' means end of line).

That's it really.

A.
Dec 1 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: fartsniff | last post by:
hello all, here is a preg_match routine that i am using. basically, $image is set in some code above, and it can be either st-1.gif or sb-1.gif (actually it randomly picks them from about 100...
1
by: Daniel | last post by:
I've been searching the net and Google news groups for a preg_match expression that will return true on strings containing (uppercase and lowercase) characters of A-Z, 0-9 and for instance Swedish...
10
by: aaron | last post by:
I need some help with validating an email address. Right now, I am doing this: function sys_is_valid_email ($s) { if (preg_match ("/^.+@.+\..+$/", $s)) { return 1; } else { return 0; } }
2
by: tgh003 | last post by:
I need help with a regex. Been at it for hours and need some sanity help :> I am using preg_match in PHP to strip a IMG html tag. I want to strip any IMG tag that has /work/doc?g= in the SRC...
22
by: stoppal | last post by:
need to extract all text between the following strings, but not include the strings. "<!-- #BeginEditable "Title name" -->" "<p align="center">#### </p>" I am using preg_match(????, $s,...
0
by: awebguynow | last post by:
I ran across this code, and it kind of made me nervous: (as an email validator) if ( !preg_match("/.*\@.*\..*/", $_POST) | preg_match("/(\)/", $_POST) ) 1) from bitwise experience with "C",...
5
by: Mark Woodward | last post by:
Hi all, I'm trying to validate text in a HTML input field. How do I *allow* a single quote? // catch any nasty characters (eg !@#$%^&*()/\) $match = '/^+$/'; $valid_srch = preg_match($match,...
3
by: Happy Face | last post by:
Hi, All, I encountered this strange problem while using function preg_match. The following is the php code. when I set the line: $text = str_repeat('*', 12500); preg_match will return 0 for...
8
by: Thomas Mlynarczyk | last post by:
Hello, I want to split a given string into tokens which are defined by regexes: // example tokens - a bit more complex in real $tokens = array( 'NUMBER' ='~^\d+~', 'NAME' ='~^+~', 'ANY' ...
5
by: jeddiki | last post by:
Hi, I am wanting to do a simple extraction of the three key header elements from a web page namely these: Is the preg_match() function the best way to find them and put them into variables...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.