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?

preg_match("/[A-Za-z0-9_-.]/",$text);

View 2 Replies


ADVERTISEMENT

Regex - Alphanumeric Characters Along With Underscore And Space

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:

[php]/^[a-zA-Z0-9]+$/[/php]

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

Strip All Characters Except For Alpanumeric And Underscore And Dash?

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

Validate A Username Which Can Only Be Alphanumeric And Underscore

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

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

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?

'#((w+://)?(w+.)([a-z0-9-/.?=_&%])+)#i'

View 3 Replies

Regex Match If Maximum Two Occurrences Of Dot And Dash?

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

Regex - Using Preg_match To Strip Specified Underscore?

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

apsd_01_03s_somedescription
apsd_02_04_somedescription

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

View 4 Replies

Replace All Proceeding Underscores With 1 Underscore Using A Regex?

[code].....

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

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

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

Tell Regex To Match At Least X Number Of Alphanumeric?

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";
else
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

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

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

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

View 2 Replies

Regex - Replace All Non Alphanumeric Characters With Space?

$html=strip_tags($html);
$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

Regex Validate Alphanumeric String With Slashes?

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

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

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

Regex - Regular Expression For Alphanumeric And Hypen Input?

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

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

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

Regex - Simple Form Validation And The Validation Symbols?

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

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

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

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

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

Regex - Alphanumeric Or "-" Characters

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

Regex For Url Validation?

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:

/^(https?)://(?:[A-Z0-9-]+.)+[A-Z]{2,6}([/?].+)?$/i

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

View 3 Replies

Password Validation Regex

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

Password Validation Regex

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

Validation Using An Regex Array?

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

Regex Pattern For URL Validation?

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 :

**example.com**
CONVERT -> url
**www.example.com**
CONVERT -> url
**subdomain.example.com**
CONVERT -> url
**http://subdomain.example.com**
CONVERT -> url

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

View 2 Replies

Regex For Utf-8 Filename Validation?

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







Copyrights 2005-15 www.BigResource.com, All rights reserved