This question already has answers here:
Closed 11 years ago.
Possible Duplicate:
PHP regex to check a English name
I'm trying to write a regular expression that will check a name field that i have for a user.
I want it to check for
Firstname SPACE Middle initial SPACE Last name.
I know for singular letters for the middle intitial I'll need [a-z] but I'm not sure how to do the full words for first and last name and the spaces in between.
You might want to use str_word_count() to make it a bit easier for your self.
Also, to check for names you might want to add more letters than just a-z, you should take a look at the answer in this question.
Name may contain - symbol. /^[\-a-z]+\s[\-a-z]\s[\-a-z]+$/i
^[A-Za-z]+\s[A-Za-z]\s[A-Za-z]+$
Related
This question already has an answer here:
html5 pattern for first and last name
(1 answer)
Closed 5 years ago.
I tried below pattern for Name field in HTML5, but everytime I am getting error :- "Please match the requested format"
Apart from above pattern, I also gave different pattern like :-
a) pattern="/^[A-Za-z\s]+$/"
b) pattern="/^[A-Za-z]\s[A-Za-z]+$/"
All the three pattern are not working. What I want is simple Firstname Lastname like "Harry Potter".
Please advice.
Thanks in advance.
You need to remove leading and trailing slashes from your pattern because in JavaScript they're indicate that string is actually a regular expression, but in html attribute it is already known to be a regular expression.
Pattern itself will depend on what kind of names you want to accept, your expression will not accept non-latin names, but there is a lot of people with such names. Basically if you want to check for existence of at least 2 words (since name can contain more then 2 words). For example you can use this pattern="\D\S+(\s+\D\S+)+" that will check for existence for at least 2 words separated by whitespace and each word should not start with a digit.
This question already has answers here:
Is there any way to change input type="date" format?
(21 answers)
Closed 6 years ago.
This may be a poorly worded question because I'm not sure of the lingo but allow me to explain.
I have a form field on my website where the user inputs a date (DOB.) I need the date in a specific format (MM-DD-YYYY.)
As of right now, the PHP is able to reject dates not in this specific format. (E. g. M-D-YY or MM/DD/YYYY) It will only accept and store MM-DD-YYYY which is exactly what I want. No problem here.
However, for the sake of making it easier for the user to understand, I would like to add a sort of placeholder inside the field. (E. g. _ - - _ _ _ ) So, as the user is typing those underscores turn into numbers and it skips the hyphens and the user can easily see the date is accurately entered.
March 4, 1982 for example must be 03-04-1982. If the user tries to enter 3-4-1982 what they will actually get with the pre-inserted underscores and hyphens is 34-19-82_ _. The user can easily see this is incorrect.
So, with all that said, the caveat is it MUST be done with PHP (HTML and CSS) only. I know this is possible with javascript but what is required by the webowner is to be javascript free.
Is this possible?
FYI - I am neither the programmer or website owner. I am the translator between them but I am confused what we can do and what we want to do.
**EDIT - Looks like the example of the placeholder text is not showing correctly on my phone. It should be:
underscore underscore hyphen underscore underscore hyphen underscore underscore underscore underscore
i think is not possible !
please see this link :
Is there any way to change input type=“date” format?
This question already has answers here:
how to replace special characters with the ones they're based on in PHP?
(8 answers)
Closed 8 years ago.
I am trying to parse a string, split it on what is not a letter or number
$parse_query_arguments = preg_split("/[^a-z0-9]+/i", 'København');
and construct a mysql query.
Even if I skip the preg_split and try to enter the string directly it breaks it into 2 different strings, 'K' and 'benhavn'.
How can I deal with these issues?
If you're using literal characters like a-z then it won't match accented ones. You might want to use the various character classes available to do more generic matching:
/[[:alpha:][:digit]]/
The [:alpha:] set is much broader in scope than a-z. Remember character matching is done based on character code, and a-z in order take, literally, characters between a and z by index. Characters like ø lie outside this range even if they'd fall between that alphabetically.
Computers work in ASCII-abetical (UNICODEical?) order.
This might help explain what is going on in your regex... Regex and Unicode.
You could try something like \p{L} as explained in this question
This question already has answers here:
Measure the pronounceability of a word?
(3 answers)
Closed 9 years ago.
Basically, if I'm given a random jumble of letters, I need to check to see if this could phonetically be considered a word.
I'm not looking to validate against a dictionary list, since I don't really care if the letters form an actual word or not. I just need to determine whether or not those letters are in the correct format to be considered a word.
For example:
aaaaaa // Not valid, because there are no consonants
bbbbbb // Not valid, because no vowels
dogcat // Valid, even though it is not a word, because it phonetically makes what could be considered a word
dapmar // Valid, even though nothing about this is a word, it phonetically works
I realize there are going to be exceptions to almost any logic given, so this doesn't have to be an exact science, I would just like to catch the majority, so the most general logic would work for me.
I think it all boils down to whether or not a jumble of letters can be pronounced easily.
Any help is appreciated, thanks!
Prevent letters to be repeated more than 3 times first, for example ccc will be invalid (or maybe you could do every letters except vowels so aaaaa, eeeee, uuuuu will be ok), then check all words from a list of existing words of your language only if you want to check something, but if you're generating a pronouncable word I don't think you'll need existing words.
Pleas also check this: pronounceability algorithm , http://10000ideas.blogspot.fr/2011/07/what-makes-word-pronounceable.html and this one : Measure the pronounceability of a word?
For the amount of time and effort it would take to write code to logically check this, you'd be better off getting a file with as many English words as possible and putting them into an array. That would be your BEST logical check.
This question already has answers here:
Closed 11 years ago.
Possible Duplicate:
PHP: How to generate a random, unique, alphanumeric string?
I'm creating the image hosting website. I need to create a unique and five letters string (case sensitive) for an image, like an example -> imgur.com/srM0U
I have seen many examples, but they are not unique or not case sensitive.
Generated string I will use for an image filename, I think imgur uses a unique strings.
Please help with a piece of code
http://kevin.vanzonneveld.net/techblog/article/create_short_ids_with_php_like_youtube_or_tinyurl/
The main thing to keep in mind is that the way most short-URL systems work is that they save the long form URL into a database, with an auto-incremented ID. That ID is then converted to an alphanumeric short code by a script similar to the one above.
The reason I point this out is I think you're approaching the problem backwards- trying to assign an alphanumeric shortcode first. It's much easier to have unique numeric values (hence, auto-increment) and then approach encoding it from there.
Sorry for the poor formatting, sent from my phone.