473,800 Members | 2,418 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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($a lphanumeric_fie ld)
{
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 1951
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($a lphanumeric_fie ld)
{
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($a lphanumeric_fie ld)
{
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
4246
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 gifs). then it processes them based off of which image type it selected, either the st- 's or the sb- 's.
1
5404
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 characters Å Ä Ö. It should return false on strings containing stuff like -#¤%\"()=?&/. The thing is, I don't want to specifically allow Å Ä Ö, I want a more general rule in case other characters like ü or ø turn up. Is this possible to do? ...
10
8173
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
6793
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 attribute. The basic one i wrote works but obviously doesnt work when you add the height/width attribute into it: "<img src=\"\/work\/doc\?g\=(+)\">"
22
2779
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, $results)
0
1342
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", I was not at all comforable with !preg_match() The manual is not clear about using ! with a non-boolean value. When using !($var) is ($var) converted to a boolean value, before
5
7556
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, $res_description); if (!$valid_srch) { ...
3
1885
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 the hard coded regular expression. but if I set $text to 12499, it will return 1 for a match. $text = str_repeat('*', 12499);
8
4002
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' ='~^.~' ); // make sure there is always a match
5
2839
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 ? If they are not found of the web page I would like to fill the relevant variable with "Not found".
0
9690
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10275
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10033
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9085
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6811
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5471
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5606
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4149
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2945
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.