Regex Validation - Use Alphanumeric As Well As Dash (-) Underscore (_) And Period (.)

Oct 30, 2009

I need to use PHP to validate usernames, and I only want them to use alphanumeric, as well as dash (-), underscore (_) and period (.) Is this right?



Regex - Alphanumeric Characters Along With Underscore And Space

Jun 6, 2007

I would like to know the regex for the following: input text can contain alphanumeric characters along with underscore and space for example: "this is user_name"
i used the following:


this works but not perfectly because when the only space bar is pressed it takes the value, i want to prevent this, space should be @ the beginning, what will be the regex for this?

View 1 Replies View Related

Strip All Characters Except For Alpanumeric And Underscore And Dash?

May 19, 2011

I'm not an expert with regexI'm trying to to strip all characters from the string except for alpanumeric and underscore and dash.Is this the correct syntax?:

preg_replace("/[^a-z0-9_-]+/i", "", $string);

View 3 Replies View Related

Validate A Username Which Can Only Be Alphanumeric And Underscore

Dec 30, 2005

I need to validate a username which can only be alphanumeric and maybe contain an underscore. I wrote this:

function validate_username($v_username) {
return (eregi("[a-zA-Z0-9]",$v_username));
which does not validate "#$%" but does validate "Ann#$%"

View 9 Replies View Related

Limit The Period To "Only Allow 1 Period Per Set Of Bracket" In The Regex?

Jun 28, 2011

I worked out this regex and its working close but only one more problem in that, it matches any word with more than one period (.)

For example: stuf... (got matched)

How do I limit the period to "Only allow 1 period per set of bracket" in the regex?


View 3 Replies View Related

Regex Match If Maximum Two Occurrences Of Dot And Dash?

Jul 1, 2011

I need a regular expression that will match any string containing at most 2 dashes and 2 dots.
There does not HAVE to be a dash nor a dot, but if there is 3+ dashes or 3 dots or even both 3+ dashes and 3+ dots, then the regex must not match the string.Intended for use in PHP.I know of easy alternatives using PHP functions, but it is to be used in a large system that just allows filtering using regular expressions.

Example string that will be MATCHED:
Example string that will NOT be matched

View 3 Replies View Related

Regex - Using Preg_match To Strip Specified Underscore?

Apr 15, 2010

There has always been a confusion with preg_match in php. I have a string like this:


Can I use preg_match to strip off anything from 3rd underscore including the 3rd underscore.

View 4 Replies View Related

Replace All Proceeding Underscores With 1 Underscore Using A Regex?

Apr 20, 2011


PS: The reason a preg_replace (regex) is preffered (although I understand its not 100% always correct) because it's more precise then using a regular string replacing function.

View 3 Replies View Related

Regex - Check If The String Only Consist Letters A - Z And Numbers And Underscore(_) And Hyphen(-)

Aug 3, 2009

I'm looking for a regex that will check if the string only consists of the letters a-z, numbers, underscore (_) and hyphen (-). I have tried this, but it does not work:

if (!preg_match('/^a-zA-Z0-9_-$/', $string)) {
$reg_Error[] = 2;

Also, can I check the length with regex? If not, I will just do it with PHP.

View 5 Replies View Related

Tell Regex To Match At Least X Number Of Alphanumeric?

Mar 13, 2010

I have form where user submits field. Field can have letters, numbers, and punctuation. But I want to check to make sure that at least 3 of the characters are letters. How can I regex that? For example,

$string = "ab'c";

And I need something like,

if (preg_match("/[a-z]{3}/i", $string))
print "true";
print "false";

That string has three letters, even though it has an apostrophe. It should test true. But for some reason, that tests false right now.

View 4 Replies View Related

Regex - Remove Last Character If It's A Period?

Jan 13, 2010

How to remove the last character only if it's a period?

$string = "something here.";
$output = 'something here';

View 2 Replies View Related

Regex - Replace All Non Alphanumeric Characters With Space?

Apr 5, 2011

$html=ereg_replace("[^A Za-]"," ",$html);
$words = preg_split("/[s,]+/", $html);

doesnt this replace all non (A-Z, a-z, a o u with umlauts) characters with space? I am losing words like zugnglich etc with umlauts. is there any thing wrong with the regex? I replaced ereg_replace with preg_replace but somehow the special characters like:, are not getting replace by spacE

View 4 Replies View Related

Regex Validate Alphanumeric String With Slashes?

Oct 29, 2010

May be I got up on the wrong side of the bed but why this simple regex doesn't work ?

PHP Code:
if (preg_match("#^[0-9a-z/]+#i", "/user/1/***")) {
echo "A match was found.";
} else {
echo "A match was not found.";
// give A match was found.

View 4 Replies View Related

Regex - Add A Space Between A Period And The Next Word/letter When There's None?

May 19, 2010

I need to use php to add a space between a period and the next word/letter when there's none.For example, "This is a sentence.This is the next one." needs to become "This is a sentence. This is the next one." Notice the added space after the first period.My problem is that even if I'm able to make a regular expression that finds every dot followed by a letter, how do I then replace that dot with a "dot + space" and keep the letter?

View 3 Replies View Related

Regex - Regular Expression For Alphanumeric And Hypen Input?

Nov 12, 2010

Is it possible to validate input depending on whether it only contains a combination of letters, numbers and hyphens (where a hyphen is not repeated twice-in-a-row and does not begins/ends the string)? Thanks to [PHP] Validate username as alphanumeric with underscoresI know that the following validates a string based on alphanumeric input with underscores, would it be possible to alter this?

function validate_alphanumeric_underscore($str)
return preg_match('/^[a-zA-Z0-9_]+$/',$str);

View 4 Replies View Related

Put URLs From String Into Array Using Regex ( Trailing Period )?

Nov 23, 2010

I am trying to write a function that pulls all url's from a string and remove a potential trailing slash from the end.

function getUrls($string) {
$regex = '/https?://[^" ]+/i';
preg_match_all($regex, $string, $matches);
return ($matches[0]);

View 3 Replies View Related

Regex - Simple Form Validation And The Validation Symbols?

Feb 5, 2009

I want to use some basic php validation (regular expressions) on, how do you go about doing it? I have just general text input, usernames, passwords and date to validate. I would also like to know how to check for empty input boxes. I have looked on the interenet for this stuff but I haven't found any good tutorials.

View 6 Replies View Related

Input String $foo Which Contains Both Alphanumeric And Non-alphanumeric Characters?

Jun 26, 2011

I have an input string $foo which contains both alphanumeric and non-alphanumeric characters.I use ereg_replace to $foo to replace all non-wanted chars with empty chars. Now I want to know what were these "erased" chars. How can I do this?

View 4 Replies View Related

Regex Using Preg_replace : "Delimiter Must Not Be Alphanumeric Or Backslash" Error?

Mar 27, 2010

I am trying to take a string of text like so:

$string = "This (1) is (2) my (3) example (4) text";

In every instance where there is a positive integer inside of parentheses, I'd like to replace that with simply the integer itself.The code I'm using now is:

$result = preg_replace("((d+))", "$0", $string);

But I keep getting a "Delimiter must not be alphanumeric or backslash" error. Any thoughts? I know there are other questions on here that sort of answer the question, but my knowledge of regex is not enough to switch it over to this example.

View 4 Replies View Related

Regex - Alphanumeric Or "-" Characters

Aug 25, 2001

I'm trying to check and see if a user's input has alphanumeric or "-" characters (ONLY), followed by a period, then by alpha characters. Also, the dash cannot start or end the section before the period. I havent had a lot (read: any) experience with regex, so after a while searching through some threads here Im lost beyond belief.

View 5 Replies View Related

Regex For Url Validation?

Nov 28, 2010

Possible Duplicate: PHP validation/regex for URL in my form I have a url field. The user my input all kind of web url's. I use the following regex to validate the url:


But this regex handles some url's as invalid, e.g. the following[URL].....

View 3 Replies View Related

Password Validation Regex

Jun 29, 2006

I have a problem regarding the password validation. I want my users to input a password consisting of alphanumeric characters which is at least 6 characters and must consist of upper and lower chars. Here is my code

if (!eregi('^(?=.*d)(?=.*[a-z])(?=.*[A-Z]).{6,16}$',$reg_password))
$error_msg[] = "<font color='red'>Error! </font>Invalid password format.";

It gives out an error message:
Warning: eregi() [function.eregi]: REG_BADRPT in .

View 1 Replies View Related

Password Validation Regex

Jun 29, 2006

I have a problem regarding the password validation. I want my users to input a password consisting of alphanumeric characters which is at least 6 characters and must consist of upper and lower chars. Here is my code:

if (!eregi('^(?=.*d)(?=.*[a-z])(?=.*[A-Z]).{6,16}$',$reg_password))
$error_msg[] = "<font color='red'>Error! </font>Invalid password format.";

It gives out an error message:

Warning: eregi() [function.eregi]: REG_BADRPT in.

View 1 Replies View Related

Validation Using An Regex Array?

Feb 14, 2011

I am working on creating an array of regular expressions based on form values and using a function that fails on the wrong user input. Every time I run the website I receive the following error:

Warning: eregi() [function.eregi]: REG_EMPTY

I do not know what is wrong.

$error_log = array();
// Checks if user inputed data matches the default values
$arr = array( [code]....

View 1 Replies View Related

Regex Pattern For URL Validation?

Jan 8, 2011

I'm using this PHP function for validate an URL.

$url = preg_replace("/[^A-Za-z0-9-/.:]/", "", trim($url));
$url = preg_replace('%^(?!https?://www.).*%', 'http://www.$0', $url);

But, this isn't perfect for me. I want to this controls :

1 - Is it starting with http:// or https:// ? If not, add http (or https)

2 - If it hasn't subdomain and if it hasn't www , add . But if it has subdomain don't add www.

Examples :

CONVERT -> url
CONVERT -> url
CONVERT -> url
CONVERT -> url

So, i need improve my REGEX pattern. But i can't. How can i use this ?

View 2 Replies View Related

Regex For Utf-8 Filename Validation?

May 22, 2011

I have been googling around for a couple of hours but I couldn't find a good solution for utf-8 filename validating PHP regex solution. I have tried many of them, if needed I may copy/paste here. File name may include german or other characters but not invalid ones like / etc.

View 4 Replies View Related

Regex For Email Validation?

Apr 13, 2010

I've been searching the web for ages now and still cannot find a proper working perl regex to validate email addresses. Its kinda urgent so if you could help me that would be great!!
After playing around with bits i found i got this:

PHP Code:

View 1 Replies View Related

Regex - UTF-8 Validation Without Using Preg_match()?

Aug 15, 2009

I need to validate some user input that is encoded in UTF-8. Many have recommended using the following code:

| [xC2-xDF][x80-xBF]
| xE0[xA0-xBF][x80-xBF]
| [xE1-xECxEExEF][x80-xBF]{2}
| xED[x80-x9F][x80-xBF]
| xF0[x90-xBF][x80-xBF]{2}


Yes, it's very long. I hope I've understood correctly how that regular expression works.

View 5 Replies View Related

A Regex For Password Validation?

Aug 16, 2008

i need a regex for password validation. password should contain

atleast 1 capital
atleast 1 small
atleast 1 specialchar
atleast 1 number

i'm trying with following ....

$regex="/[A-Z]/"; regular expression

if (!preg_match($regex,$sPassword)[code]....

but it's not working

View 14 Replies View Related

REGEX Validation Of Postal/Zip Codes

Nov 15, 2000

I'm looking for a regex matching idea for validating a postal/zip code. Namely we'll be checking US, Canadian and Mexican postal/zip codes.

View 2 Replies View Related

Ip Address Validation Regex Fails

Jul 15, 2004

I have the following rexeg to validate an ip address. The thing I'm going crazy is that this regex does work perfectly when tested with The Regex Coach program, but when in php, it simply doesn't match.....

View 1 Replies View Related

Regex - Phone Number Validation

May 19, 2010

I need to validate phone number in PHP. I have made following regex, but I also need to it to accept numbers starting with plus char, how can I do that?


View 2 Replies View Related

Twitter Username Regex Validation?

Dec 12, 2010

i use this pattern /[a-z0-9_]+/i with this function:

function validate_twitter($username) {
if (eregi('/[a-z0-9_]+/i', $username)) {
return true;

to test if the input is a valid twitter username, but it never gives me a valid result?

View 5 Replies View Related

Timezones Validation Regex Not Working (getting Not Valid)

Jul 12, 2011

I'm trying to validate timezones. Example:


So - UTC will stay the same, sign will be alternating(+ or -) and number varies from -12 to +14.

I don't understand why this regex not working (I get not valid):

$val = 'UTC+12';
$range = '-11:30|-11|-10:30|-10|-9:30|-9|-8:30|-8|-7:30|-7|-6:30|-6|-5:30|-5|-4:30|-4|-3:30|-3|-2:30|-2|-1:30|-1|-0:30|+0|+0:30|+1|+1:30|+2|+2:30|+3|+3:30|+4|+4:30|+5|+5:30|+5:45|+6|+6:30|+7|+7:30|+8|+8:30|+8:45|+9|+9:30|+10|+10:30|+11|+11:30|+12|+12:45|+13|+13:45|+14';
$regex = '/^UTC(+|-)(' . $range . ')/';
if(preg_match($regex, $val)){
echo 'valid';
echo 'not valid';

UPDATE: silly me. so simple. I forgot that I already use signs in my $range array. so stupid. I don't even have to check for sign inside of my regex.

$regex = '/^UTC(' . $range . ')/';

View 1 Replies View Related

Regex - Email Validation Using Preg, NOT Ereg?

Aug 31, 2010

For PHP what is the best email validation using preg, NOT ereg because it's deprecated/removed.I don't need to check if the website exists (it's not like maximum security).I've found many ways with ereg but they (obviously) aren't good practice.

View 4 Replies View Related

Regex - Handle Validation Of Non - Latin Script Input?

Jun 26, 2011

I am trying to adapt a php application to handle non-latin scripts (specifically: Japanese, simplified Chinese and Arabic). The app's data validation routines make frequent use of regular expressions to check input, but I am not sure how to adapt the w character type to other languages without installing additional locales on the system (which I cannot rely on).

Previous developers to have worked on the app have simply added needed characters to the regexes as the number of languages we supported grew (you frequently see "[... etc" in the code), but I can't really do this for all the alphabets I need to support now. Does anybody out there have some advice on how to tackle this?

View 1 Replies View Related

Month Regex Validation Function PreveriDatum($string)?

May 22, 2011

function preveriDatum($string)
if (preg_match("^(3)?(?(1)[0-1]|(0)?(?(2)[1-9]|[12][0-9])).(0)?(?(3)[1-9]|1[0-2]).[1-9][0-9]{3}$^", $string))
return true;
return false;
is valid for 13.01.2010 but not for 13.1.2010. Can i aso make it valid for 13.1.2010?

View 3 Replies View Related

Regex - Mail Validation With Filter_var() Or With Regular Expression?

Oct 30, 2010

I have learned today, that it is possible to validate e-mail two ways. One way is by regular expression and the other is by filter_var() function.

If anyone could tell me how strong the validation with filter_var is and if there are any recommendations or suggestions on thoughts about switching from regular expression to it, then it would be just great.

View 2 Replies View Related

Regex - Form Validation Regular Expression No Symbols Or Numbers

Mar 22, 2010

I am trying to get the users First Name the form gets their name perfectly fine and posts it into a variable. Now I am trying to do error checking

else if(!preg_match("/^[w-]+$/", $firstNameSignup)) {
$firstNameSignupError = "Your first name cannot contain numbers or symbols, you entered " . $firstNameSignup;
$firstNameSignup = "";

I tried the above code and it does not like me but my if statement

if(!isset($firstNameSignup) || $firstNameSignup == "") {
$firstNameSignupError = "You must enter your first name";

works fine so I know that the error is in that else if statement

View 2 Replies View Related

Regex Validation Doesn't Work As Intended In Sticky Form

Jan 23, 2010

I have a regex pattern that seems to work wel in itself, but that does not work as intended in a sticky form The following regex validation script, which test for a match between the 'lvion' string and the '/^[[:alnum:]]{8,12}$/i' pattern, returns 'ok', which is what is expected.


View 4 Replies View Related

Small Dash

Dec 10, 2001

how to get rid of the small dash when I used 5 echo with icons and hyperlink. there appears small dash beside each icons. how to get rid of this???

View 5 Replies View Related

Trying To Use A Function To Replace With A Dash

Jul 27, 2005

I don't know anything about php, but luckily enough, there is only one page of code. I stripped the main code, becuase I don't think its necessary to understand what I am trying to do. However if needed, I will add it. Basically, this code is a mod to convert the Invision Board urls into html. One annoying thing about this mod is that they use the separator _ which I want to convert to a dash obviously for better SEO purposes. Here is code, and I think this is what needs to be edited....

View 1 Replies View Related

Displaying A URL Slug With Dash?

Apr 15, 2010

I made a slug with dash for my stories URLs such as:[URL]..This is my code to create slug :

function Slugit($title) {
$title = strip_tags($title);
// Preserve escaped octets.
$title = preg_replace('|%([a-fA-F0-9][a-fA-F0-9])|', '---$1---', $title);
// Remove percent signs that are not part of an octet.
$title = str_replace('%', '', $title);


As you can see dashes, up to here, everything is fine. But when I click on the link, it can not open and find it my database as it's saved in normal and with no dashes.

So I wrote something to remove dashes:

$string = str_replace('-', '&nbsp;', $string);

But when there is ? or . in URL, then it can not display!

View 2 Replies View Related

Removing A Dash From A String?

Apr 22, 2010

This should be easy but I can't figure it out.I have a string:Code: [Select]$myString = "cr-charles-rob";I want to remove the dashes ( - ) from the string so it looks like this:"crcharlesrob"hat function can I use to accomplish that?

View 1 Replies View Related

Removing A Dash From The End Of $title?

Jan 25, 2011

I'm trying to remove a dash at the end of a title, for the times when a dash appears there (which isn't always). Since my titles are always different lengths, I don't think substr will work. How can I code the following

View 5 Replies View Related