<% ' Copyright (c) 2008, <a href="http://www.thecanonman.com;" >www.thecanonman.com;</a> some rights reserved. ' ' This work is licensed under the Creative Commons Attribution License. To view ' a copy of this license, visit <a href="http://creativecommons.org/licenses/by/3.0/" >http://creativecommons.org/licenses/by/3.0/</a> or ' send a letter to Creative Commons, 559 Nathan Abbott Way, Stanford, California ' 94305, USA. ' Checks if a string contains only alphanumeric characters. function isAlphaNumeric(someString) dim regEx set regEx = new RegExp with regEx .Global = true .IgnoreCase = true .Pattern = "[ws.]" end with if regEx.test(someString) then isAlphaNumeric = true else isAlphaNumeric = false end if set regEx = nothing end function %>
Tag Archive for regular
isAlphaNumeric
isAlpha
<?php
/*
Copyright (c) 2008, reusablecode.blogspot.com; some rights reserved.
This work is licensed under the Creative Commons Attribution License. To view
a copy of this license, visit <a href="http://creativecommons.org/licenses/by/3.0/" >http://creativecommons.org/licenses/by/3.0/</a> or
send a letter to Creative Commons, 559 Nathan Abbott Way, Stanford, California
94305, USA.
*/
// Checks if a string contains only alpha characters.
function is_alpha($someString)
{
return (preg_match("/[A-Zs_]/i", $someString) > 0) ? true : false;
}
?>
isAlpha
<% ' Copyright (c) 2008, <a href="http://www.thecanonman.com;" >www.thecanonman.com;</a> some rights reserved. ' ' This work is licensed under the Creative Commons Attribution License. To view ' a copy of this license, visit <a href="http://creativecommons.org/licenses/by/3.0/" >http://creativecommons.org/licenses/by/3.0/</a> or ' send a letter to Creative Commons, 559 Nathan Abbott Way, Stanford, California ' 94305, USA. ' Checks if a string contains only alpha characters. function isAlpha(someString) dim regEx set regEx = new RegExp with regEx .Global = true .IgnoreCase = true .Pattern = "[A-Zs_]" end with if regEx.test(someString) then isAlpha = true else isAlpha = false end if set regEx = nothing end function %>
PHP (RegEx) IP Address Validation
$string = "255.255.255.255";
if (preg_match(
'/^(?:25[0-5]|2[0-4]d|1dd|[1-9]d|d)(?:[.](?:25[0-5]|2[0-4]d|1dd|[1-9]d|d)){3}$/',
$string)) {
echo "IP address is good.";
}
PHP (RegEx) Zip Code Validation
$string = "12345-1234";
if (preg_match('/^[0-9]{5}([- ]?[0-9]{4})?$/', $string)) {
echo "zip code checks out";
}
PHP (RegEx) Email Address Validation
$string = "first.last@domain.co.uk";
if (preg_match(
'/^[^W][a-zA-Z0-9_]+(.[a-zA-Z0-9_]+)*@[a-zA-Z0-9_]+(.[a-zA-Z0-9_]+)*.[a-zA-Z]{2,4}$/',
$string)) {
echo "example 3 successful.";
}
PHP (RegEx) Telephone Number Validation
$string = "(232) 555-5555";
if (preg_match('/^(?[0-9]{3})?|[0-9]{3}[-. ]? [0-9]{3}[-. ]?[0-9]{4}$/', $string)) {
echo "example 2 successful.";
}
Category: Uncategorized |
Tags: expressions, number, phone, php, regular, simple, telephone, validation
Add more text to a column of text
ls -l /etc/apache2/sites-available/ | awk '{ print $8}' | grep -v ^$ | sed 's:^[a-z]*$:blogs.&.com:'
Text Wrapping with Regular Expressions
def wrap_text(txt, col = 80)
txt.gsub(/(.{1,#{col}})( +|$)
?|(.{#{col}})/,
"13
")
end
String Matching
/*pull out all comments with specific words*/ data commentsdata;set surveydata; if _n_=1 then do; retain re; re = prxparse(’/words|to|match/i’); /* the /i here means Case insensitive match */ if missing(re) then do; putlog ‘ERROR: regex is malformed’; stop; end; end; if prxmatch(re,Comments); /* Comments is the name of the variable with the comments text */ run; /*Regular Expressions*/ /* ^ start of field s* (maybe with whitespace at the front) [A-Z] a letter from A to Z d a digit [A-Z] A to Z again a space d a digit [A-Z] A to Z again d a digit s* possible whitespace $ end of field */ data new; set YourData; if _n_=1 then do; re = prxparse(’/^s*[A-Z]d[A-Z] d[A-Z]ds*$/’); if missing (re) then stop; end; if prxmatch(re,YourNameField); run;