Q:

Alphanumeric string pattern with apostrophe allowed

I want to validate name field which excepts only alphanumeric, apostrophe and a dot(.) For example, it should allow the string abc's home99,St. Mary's Hospital but I don't want the string starting with any of the special characters or ending with it for example 'abc or abc' or g_abc 56gfhg or abc 56gfhg..
i have used 
stringPattern = /^[a-zA-Z0-9']*$/;

pattern but it allows apostrophe anywhere in the string.

A:

try this regex:
\w(\w|'|\ )*\w

you can test it here: http://regexpal.com/
but it requires the username to be at least 2 characters long

