Tag Archives: javascript

First Safari Technology Preview update drops

Safari Technology Preview, a special version of Apple’s desktop browser designed to give developers their first look at upcoming new features and future enhancements, today received the first official update since its release two weeks ago. The new build packs in a host of fixes and improvements for Safari’s layout and rendering engine, CSS, JavaScript, […]

_

(0)

37 Tested PHP, Perl, and JavaScript Regular Expressions

A regular expression, also called regex or regexp for short, is simply a piece of code that matches a pattern. Mastering regular expressions can be a difficult chore, and if you don’t need them all of the time, the syntax is tricky enough to make the task frustrating or slow as you will constantly need to use a reference sheet.

In order to save you time, I’ve compiled a list of PHP, Perl, and JavaScript regular expressions for common use cases that have been tested and are ready to go. This isn’t a regular expression tutorial or even a reference; you can think of it more as a cheatsheet for when you just need the regex but don’t want to put a lot of time into relearning regular expressions.

If you’re looking for regex tutorials or regex resources, you can find them at the end of the page as well as some additional regex resources.

Perl and PHP Regular Expressions

PHP regexes are based on the PCRE (Perl-Compatible Regular Expressions), so any regexp that works for one should be compatible with the other or any other language that makes use of the PCRE format. Here are some commonly needed regular expressions for both PHP and Perl. Each regex will be in string format and will include delimiters.

All Major Credit Cards

This regular expression will validate all major credit cards: American Express (Amex), Discover, Mastercard, and Visa.

  1. //All major credit cards regex
  2. ‘/^(?:4[0-9]{12}(?:[0-9]{3})?|5[1-5][0-9]{14}|6011[0-9]{12}|622((12[6-9]|1[3-9][0-9])|([2-8][0-9][0-9])|(9(([0-1][0-9])|(2[0-5]))))[0-9]{10}|64[4-9][0-9]{13}|65[0-9]{14}|3(?:0[0-5]|[68][0-9])[0-9]{11}|3[47][0-9]{13})*$/’

Alpha-Numeric Characters

Test for alpha-numeric characters with this regexp.

  1. //Alpha-numeric characters only
  2. ‘/^[a-zA-Z0-9]*$/’

Alpha-Numeric Characters With Spaces

Test for alpha-numeric characters and spaces with this regexp.

  1. //Alpha-numeric characters with spaces only
  2. ‘/^[a-zA-Z0-9 ]*$/’

Alphabetic Characters

This regex will test for alphabetic characters only (upper and lowercase).

  1. //Alphabetic characters only
  2. ‘/^[a-zA-Z]*$/’

American Express Credit Card

Verify Amex credit cards with this regexp.

  1. //Amex credit card regex
  2. ‘/^(3[47][0-9]{13})*$/’

Australian Postal Codes

If you need to verify Australian Postal Codes, use this regular expression.

  1. //Australian Postal Codes
  2. ‘/^((0[289][0-9]{2})|([1345689][0-9]{3})|(2[0-8][0-9]{2})|(290[0-9])|(291[0-4])|(7[0-4][0-9]{2})|(7[8-9][0-9]{2}))*$/’

Canadian Postal Codes

Tests for valid Canadian Postal Codes.

  1. //Canadian Postal Codes
  2. ‘/^([ABCEGHJKLMNPRSTVXY][0-9][A-Z] [0-9][A-Z][0-9])*$/’

Canadian Provinces

Evaluate Canadian province abbreviations with this regular expression.

  1. //Canadian Province Abbreviations
  2. ‘/^(?:AB|BC|MB|N[BLTSU]|ON|PE|QC|SK|YT)*$/’

Date (MM/DD/YYYY)

Validate the calendar date in MM/DD/YYYY format with this regex. Optional separators are spaces, hyphens, forward slashes, and periods. The year is limited between 1900 and 2099.

  1. //Date (MM/DD/YYYY)
  2. ‘/^((0?[1-9]|1[012])[- /.](0?[1-9]|[12][0-9]|3[01])[- /.](19|20)?[0-9]{2})*$/’

Date (YYYY/MM/DD)

Validate the calendar date in YYYY/MM/DD format with this regex. Optional separators are spaces, hyphens, forward slashes, and periods. The year is limited between 1900 and 2099.

  1. //Date (YYYY/MM/DD)
  2. ‘#^((19|20)?[0-9]{2}[- /.](0?[1-9]|1[012])[- /.](0?[1-9]|[12][0-9]|3[01]))*$#’

Digits

This regex will test for digits (whole numbers).

  1. //Digits only
  2. ‘/^[0-9]*$/’

Diner’s Club Credit Card

Test and verify Diner’s Club credit card numbers with this regexp.

  1. //Diner’s Club credit card regex
  2. ‘/^(3(?:0[0-5]|[68][0-9])[0-9]{11})*$/’

Emails

This email regex is not fully RFC5322-compliant, but it will validate most common email address formats correctly.

  1. //Email regex
  2. ‘/^([a-zA-Z0-9._%-]+@[a-zA-Z0-9.-]+.[a-zA-Z]{2,4})*$/’

IP Addresses

Test IP Addresses with this regular expression.

  1. //IP address regex
  2. ‘/^((?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?).){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?))*$/’

Lowercase Alphabetic Characters

This regex will test for lowercase letters.

  1. //Lowercase letters only
  2. ‘/^([a-z])*$/’

MasterCard Credit Card

Verify MasterCard credit card numbers with this regex.

  1. //MasterCard credit card numbers
  2. ‘/^(5[1-5][0-9]{14})*$/’

Passwords

Test for a strong password with this regex. The password must contain one lowercase letter, one uppercase letter, one number, and be at least 6 characters long.

  1. //Password regex
  2. ‘/^(?=^.{6,}$)((?=.*[A-Za-z0-9])(?=.*[A-Z])(?=.*[a-z]))^.*$/’

Phone Numbers (North American)

This regex will validate a 10-digit North American telephone number. Separators are not required, but can include spaces, hyphens, or periods. Parentheses around the area code are also optional.

  1. //Phone number regex
  2. ‘/^((([0-9]{1})*[- .(]*([0-9]{3})[- .)]*[0-9]{3}[- .]*[0-9]{4})+)*$/’

Social Security Numbers

If you need to validate US Social Security Numbers, use this regular expression

  1. //SSN regex
  2. ‘/^([0-9]{3}[-]*[0-9]{2}[-]*[0-9]{4})*$/’

UK Postal Codes

This regexp verifies UK Postal Codes.

  1. //UK Postal Codes regex
  2. ‘/^([A-Z]{1,2}[0-9][A-Z0-9]? [0-9][ABD-HJLNP-UW-Z]{2})*$/’

Uppercase Alphabetic Characters

This regex will test for uppercase letters.

  1. //Uppercase letters only
  2. ‘/^([A-Z])*$/’

URLs

This URL regex will validate most common URL formats correctly.

  1. //URL regex
  2. ‘/^(((http|https|ftp)://)?([[a-zA-Z0-9]-.])+(.)([[a-zA-Z0-9]]){2,4}([[a-zA-Z0-9]/+=%&_.~?-]*))*$/’

US States

Validate all 2-letter US State abbreviates with this regular expression.

  1. //US States regex
  2. ‘/^(?:A[KLRZ]|C[AOT]|D[CE]|FL|GA|HI|I[ADLN]|K[SY]|LA|M[ADEINOST]|N[CDEHJMVY]|O [HKR]|PA|RI|S[CD]|T[NX]|UT|V[AT]|W[AIVY])*$/’

US ZIP Codes

This regexp verifies US ZIP Codes, with an optional 4 number ZIP code extension.

  1. //US ZIP Codes regex
  2. ‘/^([0-9]{5}(?:-[0-9]{4})?)*$/’

Visa Credit Card

Verify Visa credit card numbers with this regex.

  1. //Visa credit card numbers
  2. ‘/^(4[0-9]{12}(?:[0-9]{3})?)*$/’

JavaScript Regular Expressions

The JavaScript version of regex is a slightly different flavor than the PCRE variety, so I’ve included those regexes in a separate section.

All Major Credit Cards

This regular expression will validate all major credit cards: American Express (Amex), Discover, Mastercard, and Visa. Note that it is not quite as precise as its counterpart Perl and PHP regex.

  1. //All major credit cards JavaScript regex
  2. ‘^(?:4[0-9]{12}(?:[0-9]{3})?|5[1-5][0-9]{14}|6011[0-9]{12}|3(?:0[0-5]|[68][0-9])[0-9]{11}|3[47][0-9]{13})$’

Alpha-Numeric Characters

Test for alpha-numeric characters with this regexp.

  1. //JavaScript alpha-numeric characters only
  2. ‘^[a-zA-Z0-9]+$’

Alphabetic Characters

This regex will test for alphabetic characters only (upper and lowercase).

  1. //JavaScript Alphabetic characters only
  2. ‘^[a-zA-Z]+$’

Canadian Postal Codes

Tests for valid Canadian Postal Codes.

  1. //JavaScript Canadian Postal Codes
  2. ‘^[ABCEGHJKLMNPRSTVXY][0-9][A-Z] [0-9][A-Z][0-9]$’

Date (MM/DD/YYYY)

Validate the calendar date in MM/DD/YYYY format with this regex. Optional separators are spaces, hyphens, forward slashes, and periods. The year is limited between 1900 and 2099.

  1. //JavaScript Date (MM/DD/YYYY)
  2. ‘^(0?[1-9]|1[012])[- /.](0?[1-9]|[12][0-9]|3[01])[- /.](19|20)?[0-9]{2}$’

Date (YYYY/MM/DD)

Validate the calendar date in YYYY/MM/DD format with this regex. Optional separators are spaces, hyphens, forward slashes, and periods. The year is limited between 1900 and 2099.

  1. //JavaScript Date (YYYY/MM/DD)
  2. ‘^(19|20)?[0-9]{2}[- /.](0?[1-9]|1[012])[- /.](0?[1-9]|[12][0-9]|3[01])$’

Digits

This regex will test for digits (whole numbers).

  1. //JavaScript digits only
  2. ‘^[0-9]+$’

Emails

This email regex is not fully RFC5322-compliant, but it will validate most common email address formats correctly.

  1. //JavaScript email regex
  2. ‘^[a-zA-Z0-9._%-]+@[a-zA-Z0-9.-]+.[a-zA-Z]{2,4}$’

Passwords

Test for a strong password with this regex. The password must contain one lowercase letter, one uppercase letter, one number, and be at least 6 characters long.

  1. //JavaScript Password regex
  2. “(?=^.{6,}$)((?=.*[A-Za-z0-9])(?=.*[A-Z])(?=.*[a-z]))^.*”

Phone Numbers (North American)

This regex will validate a 10-digit North American telephone number. Separators are not required, but can include spaces, hyphens, or periods. Parentheses around the area code are also optional.

  1. //JavaScript phone number regex
  2. ‘^(([0-9]{1})*[- .(]*([0-9]{3})[- .)]*[0-9]{3}[- .]*[0-9]{4})+$’

URLs

This URL regex will validate most common URL formats correctly.

  1. //JavaScript URL regex
  2. ‘^((http|https|ftp)://)?([[a-zA-Z0-9]-.])+(.)([[a-zA-Z0-9]]){2,4}([[a-zA-Z0-9]/+=%&_.~?-]*)$’

US ZIP Codes

This regexp verifies US ZIP Codes, with an optional 4 number ZIP code extension.

  1. //JavaScript US ZIP Codes regex
  2. ‘^[0-9]{5}(?:-[0-9]{4})?$’

Regex Tutorials

While this page doesn’t go in depth on how to learn regular expressions, I will point you to some tutorials so that if you need to modify any of the above regexes or create your own, you’ll be able to do so.

Regex Resources And Reference Sheets

There are a number of different regex cheat sheets, libraries, testers, and other resources around the web. Here are just a few of them.

(613)

8 Ways to Make Money Online

I absolutely believe the “average” person can make legitimate income online. I believe it because I’ve done it myself. At the beginning of 2010 I was not making any significant money online. Less than two years later, my husband quit his job and my online income now supports us. (My current income streams are listed on my Tools I Use page if you’re interested.)

 

Make money online

The crucial first step

If you want to make money online, my first recommendation is to start a blog or website. Let it serve as your internet home and branch out from there. Your own site is a must these days if you want to work online. Not sure how to do that? No problem, here’s my step by step guide: How to Start a Blog or Website.

Once you’ve got yourself set up with a site, it’s time to work. And when I say work, I mean it. Making money online is not a way to get rich quick. If anyone tells you differently, be extremely skeptical. Still, you can do it!

1. Turn your skill(s) into a service online.

If you have a skill (who doesn’t?), why not offer your services via the internet (a.k.a. virtually)? From counseling to administrative assistance to design to consulting and anything in between, thousands of people (myself included) are taking advantage of the internet to grow viable businesses from home. I highly, highly, highly recommend The Bootstrap VA: The Go-Getter’s Guide to Becoming a Virtual Assistant, Getting and Keeping Clients, and More!, an ebook by Lisa Morosky. This ebook blew my mind; it’s loaded with tips, resources and step-by-step instruction. It’s a steal at $12.99–it’s like a college course! Seriously, if you’re thinking about offering a service online, do yourself a favor and make this your first business investment.

2. Generate income directly from your site.

Niche blogs or websites are sites that offer some sort of helpful or entertaining information to a highly-targeted group of people. Sometimes it involves doing keyword research to find out what people are searching for in the search engines and tailoring your site to be the go-to place for that search.

If you have a highly-specialized interest with accompanying expertise you can share your knowledge and generate income from it. How? Advertising or affiliate marketing.

The absolute best tool for keyword research is Market Samurai. I know, because I’m a paying customer. If you want to see how it works, check out their very informative tutorial videos. Highly recommended.

3. Sell on Etsy.

Are you crafty? Consider selling on Etsy. You can set up your own shop for free and it’s simple to get started. It’s not so simple to stand out from the crowd, so that’s likely to be your biggest challenge. Here are some tips on how to market your shop.

4. Write for someone else.

The advantage of writing for other sites is that you get to be a part of something that’s already established. Also, you don’t have to worry about the technical aspects of running and maintaining your own site.

5. Are you a photographer? Illustrator?

Why not sell your photos on a site like iStockphoto? SomeGirl has an excellent series about how to become an iStockphoto seller. A significant portion of her family’s income comes from selling photos.

6. Like to travel?

This is clearly not for everyone, but I throw it out there because I think it’s cool and it demonstrates the freedom of working online. If you have the flexibility to travel, be a guide for The Lonely Planet like Gayle who lives in Ghana. Speaking of travel, more and more people are becoming “Location Independent” meaning, their home is wherever they feel like going next. Check out Lea & Jonathan’s story.

7. Create and sell your own tangible products (not necessarily the handmade kind).

If you have an idea for a product you’d like to sell but aren’t sure where to start, this couple tells you how they started selling wedding linens online. Their Online Store Tutorials are particularly helpful.

8. Write a book. Better yet, write an ebook.

Many bloggers have dreams of being published authors. Many have indeed accomplished that goal and their blogs were a major catalyst in doing so. If that’s you, then write and write well. Get involved in online writing communities like National Novel Writing Month(NaNoWriMo). Follow a blogger like Rachelle Gardner, a literary agent who explains the ins and outs of getting published the “traditional” way. I also recommend following Michael Hyatt, former CEO of Thomas Nelson (the biggest Christian publisher as of 2010). If that doesn’t work for you and you’d like to self-publish, try Lulu or CreateSpace (from Amazon).

But don’t overlook ebooks! Their popularity is on the rise and they are simple to create. I turned down a traditional book deal in favor of self-publishing. My ebook, Tell Your Time, started out as an experiment and has turned into something I never imagined. I’ve sold thousands of copies and counting. This has turned into one of my biggest income streams. Check out my How to Write an Ebook series to see how I did it and all the steps involved.

(457)

All The Cheat Sheets That A Web Developer Needs

No matter how good  programmer you are, you can`t memorize everything. It often happens to spend more time searching for a particular library, tag or declaration, than implementing it on our code.  To ease your work I have gathered here some of the most important cheat sheets that you will ever need. Do you have any suggestions?

HTML Cheat Sheet

 

CSS Cheat Sheets

Adobe Flash Cheat Sheets

 

ASP Cheat Sheets

PHP Cheat Sheets

MySQL Cheat Sheets

JavaScript Cheat Sheets

jQuery Cheat Sheets

Unicode Cheat Sheets

XML Cheat Sheets

mod_rewrite and .htaccess Cheat Sheets

Also, you should check out these 25 Neat CSS3 and Javascript plugins that come hand in hand with these cheat sheets.

(387)