english

learn php

learn css

learn html

learn javascript

learn php

8. regular expressions

assignments
2 minutes / 283 words

eight / assignments

assignment 8.1

write a function to strip non-email characters and leading/following whitespace from a string and convert to lowercase then check for a validly-formatted email. these are the rules an email address must follow...

  • contains only a-z, 0-9 and these special characters... @!#$%&'*+-/=?^_`{|}~.
  • is of the format name@domain where neither name nor domain contains @, starts or ends with period or contains more than one consecutive period.
  • name must not exceed 64 characters in length.
  • domain may only contain special characters - and period.
  • each segment (between periods) of domain must not exceed 63 characters in length.

the function should return either false or a validly-formatted email address.

(there are many valid answers to this and quite a few different approaches that can make this work, some using very complex regular expressions, others using arrays and string splitting. you're welcome to use anything that works.)

assignment 8.2

this is an extension of assignments 7.2 and 8.1.

apply your new email verification function to your address book to ensure all emails are correctly formatted without invalid characters or removed.

if any are not valid, print a report of which ones and their attached names.

assignment 8.3

write a function to convert any numbers up to twelve digits in a string to words. don't forget that people sometimes write numbers with spaces or commas to separate their digit groups and that different languages use different sizes of digit groups.

assume numbers with decimal points in them don't need to be converted but that numbers at the ends of sentences might end in periods.

the function should return the string with the numbers replaced or an empty string if anything other than a string of characters is provided.

learn php

learn css

learn html

learn javascript

powered by akelei. an avi sato project.