Home

Regex only letters and numbers and spaces

  • Regex only letters and numbers and spaces. The following additional characters: space, period (. Feb 15, 2012 · This will work too, it will accept only the letters and space without any symbols and numbers. PHP preg_match I am currently after a regex that will only let the user input: A-Z and a-z 0-9 . Anchor ^ and $ makes sure that whole string is a match and not part of whole string. Dec 7, 2013 · 10. Regular expressions are one of the most powerful tools in a programmer’s arsenal. This matches zero or one of digit, plus, space. Help is much appreciated. preg_replace to remove all characters except dashes, letters, numbers, spaces, and underscores 0 Is str_replace with an array the right way to format a person's last name? Jun 9, 2017 · This regular expression is using lookaheads. – KisnardOnline. Preg_replace non-alphanumerics and special Dec 27, 2018 · How to restrict textbox in html to only accept letters with space? 1 HTML5 Regex Pattern for textbox validation: allow alphabet, spaces, and certain characters only Regular Expression To Match Only Alphabets And Spaces. This is typical, but if you wanted allow underscores, that could be addressed as well. match() (it returns an array with what has been matched), it's better to use RegExp. \d means "any digit", and \D means "any non-digit ". The problem with this: ^[a-zA-Z]*[a-zA-Z0-9]+$ is that you are using the * operator, which denotes 0 or more repetitions. regex. To accept exactly one digit, just remove the *. Dec 19, 2016 · Somebody wasn't very smart. 0. [A-Za-z0-9\s@]* - zero or more ( *, if you do not want to match an empty string, use +, 1 or more) occurrences of ASCII letters, digits, any whitespace and @ chars. info Mar 13, 2015 · In a table column in string we can have numbers/special chars/white spaces. Dec 26, 2013 · Easiest: /^[a-z][a-z0-9]*$/i. it allows me to enter [ ] or \ which I don't want ALSO the 0,3 was not part of the question, i am using the document for that, which works great. matches(regex); but it is not working properly. Strictly speaking, you should probably also escape the . Jan 4, 2019 · New to regex. That means it does not accept any symbol besides numeric values and spaces. 0. ), comma (,), plus (+), and dash (-) I can write a pattern easily enough for the first two criteria, but the third one is more difficult. means "space", and [^ ] means "any non-space ". string str = "Abcáàéèó"; bool result = str. But with the regex /^[a-zA-Z '. Aug 7, 2015 · NODE EXPLANATION ----- ----- [\p{Alnum} ]+ any character of: letters and digits, ' ' (1 or more times (matching the most amount possible)) Additionally, if you plan to use the regular expression very often, it is recommended to use a constant in order to avoid recompile it each time, e. \s matches any whitespace. $ - end of string (replace with \z if you do not want to match if the matching string ends with \n char). We will provide a breakdown of the regex pattern and explain how it works. would somebody help me to fix please. Number is mandatory in the string but other charterer is optional. – Michael. Using + will allow many characters. Nothing before. Letters A - Z; Letters a - z; Numbers 0 - 9; The input length must be a least 2 characters and maximum 20 characters. isalnum()` filters in only letters and digits. In my validation code I have: validates :name, :presence => true, :format => { :with => regex } # Here I should set the 'regex' How I should state the regex? May 24, 2013 · 6. The forward slashes / / mark the beginning and end of the regular expression. ,!"'/$). Validation includes: Name not allow numbers. You need to make \pL only a little bit harder to type than \w. Aug 27, 2020 · 1. Note that for both regex I have included the ^ and $ operator which mean match at start and end. # )(*&amp;^%$@!,) I have been trying several things but Nov 5, 2012 · Regex - Number, character and space only. \p {L} is a design bug. – tchrist. ( I need special character only for the middle name) So I tried following regular Nov 10, 2020 · I am not good at regular expressions. IsLetterOrDigit)); This will remove everything that is not a letter or digit, and can be placed in the TextChanged event. and i tried the following. Text = string. which accepts only only Arabic characters while I need Arabic characters, Spaces and Numbers. Just add a space: [a-zA-Z0-9 ] (see the space after the Jul 27, 2017 · The field I am authorizing is the name of a book. net's number parser (for the various NumberStyles, see MSDN ): I need a regular expression for the name field which only allows letters, apostrophes, full stops, commas and hyphens. Matches any whitespace character (spaces, tabs, line breaks). The regular expression should expect the string to start with one or more lower case letters and/or underscores optionally followed by a white space and more text. \p{L}: any kind of letter from any language. !? Regular Expression only allow alphanumeric plus other specific characters. # The `if x. Sep 10, 2011 at 18:43. ^[a-zA-z\s]+$ ^ asserts position at start of the string Match a single character present in the list below [a-zA-z\s] Oct 25, 2013 · This will keep numbers and spaces. In that case, you can get all alphabetics by subtracting digits and underscores from \w like this: \A[^\W\d_]+\z. I dont want to allow any other characters but letters spaces and numbers. The set approaches are usually worst, beating regexes only for the empty string case. java. I also want to enable space in the input, but only space, not new line, etc. I need to validate an input so that it matches only these criteria: Letters A-Z (upper and lowercase) Numbers 0-9. Then, you say it should still succeed if there is ' or " . See regular-expressions. 2. ), apostrophe ('), and space. [a-z0-9]* - find any sequence of characters either between a to z including, or between 0-9 including (the "any sequence" part is the * in the end) $ - string Apr 19, 2012 · If you only want to allow digits and commas, ^[-,0-9]+$ is your regex. 8x faster than compiled Regex for all letters, and 3x faster than compiled Regex for all letters with IgnoreCase option (!). C# Regular expression for combination of space, alphanumeric and special characters 5 Regular Expression to match a group of alphanumerics followed by a group of spaces, making a fixed total of characters May 22, 2012 · At the start of the string there must be at least one letter. \s*\S. If I put the string in a IF clause, it will only be valid if it contains only numbers, letters and white spaces Oct 8, 2012 · 1. 93 2 14. If you need to pull this out of a string and it doesn't Nov 21, 2014 · PHP only letters, numbers, spaces remaining in string. I'm looking to only have one space between words. (?!\s+$) - a negative lookahead that fails the match if there are 1 or more whitespaces and end of string immediately to the right of the current location. \w matches any "word character", defined as digits, letters, and underscores. \p {L} is 5 chars and \pL is 3. @"^\w+$". Updated this question. Eg. Apr 25, 2013 · I need a regular expression to match strings that have letters, numbers, spaces and some simple punctuation (. The \D*\d is being repeated 5 times, to ensure exactly 5 digits are in the string. To avoid a partial match, append a $ to the end: ^[0-9]*$. My code for adding method in jquery validor: ECMAScript (JavaScript) This regex matches only when all the following are true: password must contain 1 number (0-9) password must contain 1 uppercase letters password must contain 1 lowercase letters password must contain 1 non-alpha numeric number Submitted by qho - 6 years ago (Last modified 10 months ago) 17. Apr 19, 2015 · 88. isalnum() which chekcs if its either letter or digit: text = "1212kk , l". answered May 30, 2014 at 11:21. String regex = "/^[0-9A-Za-z\s\-]+$/"; sampleString. : Aug 27, 2015 · 2. If you are using a POSIX variant you can opt to use: ([[:alnum:]\-_]+) But a since you are including the underscore I would simply use: ([\w\-]+) Mar 3, 2024 · We called the RegExp. 1. answered May 24, 2013 at 8:28. m4v\")kMDItemAudioBitRate . I need to use System. Indicates whether the specified Unicode character is categorized as an alphabetic letter. That means, value " 100-C09D10 A " must also be possible to enter. Note that the hyphen is escaped using \, otherwise it is used to specify a range like a-z (characters from a to z ). and (), too, since those have special meaning in regular expressions. * - 0 or more chars other than line break chars, as many as possible. – Charles Duffy Feb 19, 2015 at 23:07 Check if a string only contains numbers Match elements of a url Url Validation Regex | Regular Expression - Taha Match an email address Validate an ip address nginx test Match or Validate phone number Match html tag Find Substring within a string that begins and ends with paranthesis Blocking site with unblocked games Jul 2, 2015 · If you also want to add Unicode support, @"^[\w. reformat your regex into this: ^[A-Za-z\\s]{0,3}$. After which you apply a rule : If you dont allow numbers, it means that everything except numbers is allowed. Make your rules/requirements. asked Nov 11, 2017 at 15:00. If you have ever attempted to create your own regular expression to match only alphabets and spaces, you might find this article useful. # Option 1: # The `x for x in text` goes on string characters. Using \w can match both letters and digits, so using (?:\w){9,}, which can be written as \w{9,} can also match only letters or only underscores. log (onlyLettersAndNumbers(str1)); // true This is for use with a JavaScript function. If you want it to start with a letter, just use this: ^[a-zA-Z][a-zA-Z0-9]*$. @"^[a-zA-Z]+$". The regex you are using is pretty good. -]+$/ following strings are also accepted: tavish. The extension must be at least one character long and must contain only letters and numbers. So the name can't be " L", notice the space, whereas "L L L" is completely acceptable. * - zero or more whitespaces, a non-whitespace, and then any zero or more chars Nov 9, 2018 · Regex, every non-alphanumeric character except white space or colon. From the MDN Docs, the function returns -1 if there is no match. Jul 13, 2015 · I am trying to make a regular expression that validates letters, numbers and spaces ONLY. g. [a-zA-Z0-9]+ One or more letters or numbers. and the 3rd column to grab only non-space characters: Leaves: letters, numbers, spaces, . A Regex that only allows letters and spaces, excluding any special characters. The search function takes both strings and regexes, so the / are necessary to specify a regex. Nov 9, 2011 · I need a regex for javascript that includes a-z, A-Z, and spaces For example, the string "Bob says Hi" would be accepted, but not "There were 4 clowns" The closest I've gotten is /^[a-zA-Z]+$/ which includes a-z and A-Z but not spaces. Use the str. Dec 20, 2016 · It's exactly what you're trying to do just more concise. Apr 25, 2012 · @nam Running a test against the CMU Pronunciation Dictionary (all letters only, average length 7. Groups multiple tokens together and creates a capture group for extracting a substring or using a backreference. Matches any digit character (0-9). First, check against the regular expression ^[A-Z0-9 ]*$ which checks that you have only letters, numbers, and spaces. IsLetter. Jan 17, 2013 · Regular Expression: Allow letters, numbers, and spaces (with at least one letter not number) 3. That means that empty string does not violate the condition. Acts like a boolean OR. Nov 11, 2017 · 1. [a-zA-Z0-9]+ matches any letters or numbers one or more times. To check if a string contains only letters and numbers in JavaScript, call the test() method on this regex: /^[A-Za-z0-9]*$/. Text. Numbers are not required to be in Arabic. I dont want any special characters accepted (i. This restricts the display of alphabets, making only numbers visible for inputs. All are allowed. After that, we can concatenate it back to a string. Also he can put _ between strings example: Hello_World123 This can be possible string. . What I currently have is: Which allows letters and numbers between 5 and 40 chars, but I don't know how to also allow spaces in it. I am validating a input filed. If you need to allow specific special characters, simply include them in the character class: "^[a-zA-Z\-]+$". \d+ matches any digit one or more times. May 30, 2014 · EDIT: After seeing your change, something like so should work for you: ^[a-z0-9_]+(\s[a-z0-9_]+)*$. Feb 4, 2015 · 3. answered Jan 26, 2018 at 10:33. [a-z]{1,15} matches rest of the letters. 262k 69 504 498. If there are spaces, it will fail. I tried using /^[a-zA-Z]*$/ but this doesn't allow spaces. @tchrist BUT in the end it less than double the length of the "expression". Thank you Dec 9, 2015 · This regex will match: ^ - start of string [a-zA-Z ]* - 0 or more characters that are ASCII letters or a regular space (to match all whitespace, use \s and to match all Unicode letters, use \p{L}\p{M}) $ - end of string The / starting and ending the regular expression signify that it's a regular expression. , ! ? So basically anything in a typical paragraph or web article. This is what your current RegEx is showing but if you want to truly only have letters like you specify: You can add the RegEx character \s to your regular expression, allowing spaces, whitespace and line breaks: ^[a-zA-Z\s]*$ Or, like the other posters said, use a space, to only allow spaces: ^[a-zA-Z ]*$ I'm using the following Regex ^[a-zA-Z0-9]\s{2,20}$ for input. Hi, I would like to ask if there is a regex syntax that helps replace unwanted characters and keep only alphabets, numbers and spaces. I found the following expression: ^[\u0621-\u064A]+$. Jan 26, 2018 · The pattern matches: ^ - start of the string. user1319501. – Andrei Sep 20, 2012 at 12:18 Dec 1, 2017 · ^ asserts that the regular expression must match at the beginning of the subject [] is a character class - any character that matches inside this expression is allowed; A-Z allows a range of uppercase characters; a-z allows a range of lowercase characters. Then there can be a space followed by at least one letter, this part can be repeated. Then, check against the regular expression [A-Z][A-Z0-9 ]*\d|\d[A-Z0-9 ]*[A-Z] which checks for at least one letter ([A-Z]) and one number (\d), with both orders allowed. Reading the requirements, you can match 9 or more times a letter or a digit and make sure that the string does not contain only letters using a negative lookahead if that is supported. RegularExpressions. Besides, to validate a whole string, you need to use anchors, or a method that anchors the match at start and end of the string. explanation of the expression: / - open expression. If you need to Feb 8, 2012 · 2. Jul 20, 2011 · I am using Ruby on Rails 3. /^[a-zA-Z ]*$/. Name field also should not allow more than 150 characters. Any help would be much appreciated! Dec 15, 2016 · [a-z\d] - match any letter from a-z or number from 0-9 once [a-z\d-] - match any letter from a-z, number from 0-9, or dash zero or more times [a-z\d] - match any letter from a-z or number from 0-9 once \z - match end of string; i flag - make matches case-insensitive; Note: this will only work for strings of length 2 or more. I need to save in a string only numbers and letters and white spaces. Dec 22, 2010 · 5. Dec 20, 2012 at 13:35. Basically, it gets the text, splits it into characters and only pick what is a letter or digit. | Alternation. Last thing I have problem with is that I want to enable characters such as !@#$%^&*) Mar 19, 2012 · You could use two regular expressions. 4 chars), this is 1. Matches the expression before or after the |. These are really hard to understand! regex. The square brackets [] are called a character class. # The `''. The caret ^ matches the beginning of the input, whereas the dollar $ matches the end of the input. Jan 6, 2015 · textBox1. edited May 4, 2018 at 14:33. just change 3 to your desired length. Sep 5, 2022 · The RegExp test () Method. \A matches at the start of the string, \z at the end of the string ( ^ and $ also match at the start Dec 30, 2014 · I am using jquery validator where I have added a method to validate a string which allow only numbers, spaces, plus sign, hyphen and brackets. \s Whitespace. These are zero-width pattern matchers, which means both parts of the pattern are "anchored" to the start of the string. [a-z] - find only one character between a to z, including. If all the characters belong to the universal set. Preg_match don't allow letters and allow 0-3 numbers for given regular expression. But if you want to accept every character except numeric characters, it might be simpler to simply use: "^\D+$". If you really just want to keep a section that contains only letters and numbers, you should use the reverse logic: select what you want and replace everything but Regular expression tester with syntax highlighting, explanation, cheat sheet for PHP/PCRE, Python, GO, JavaScript, Java, C#/. Otherwise, it returns false. Escape that and at least some of the bugs should be fixed. If you also want to allow spaces, use ^[-,0-9 ]+$. If you want only letters - so from a to z, lower case or upper case, excluding everything else (numbers, blank spaces, symbols), you can modify your function like this: Your regex ^[0-9] matches anything beginning with a digit, including strings like "1A". Here is my string: "_kMDItemOwnerUserID = 99kMDItemAlternateNames = ( \"(500) Days of Summer (2009). Also note: that this works for only a-z, A-Z. All(char. Also please specify what language are you using? Nov 3, 2021 · 2. What you do with the result inside the statement or if you want to switch the statement to !==, and if you write it to console even only for testing or development - does this really matter? May 3, 2024 · If you wish to use a regex constraint on a number in a text type question, make sure you always have the value numbers under the appearance column. Hint - Apply set theory. I have ^[A-Za-z0-9 _]*[A-Za-z0-9][A-Za-z0-9 _]*$ and it works well for alphanumeric and spaces but not punctuation. So for example I have a city name like New Orleans so only letters and one space between words should be allowed. <text field only accept numeric values and spaces>. That would match from the beginning of the string ^ one or more whitespaces or a digit using a character class [ 0-9]+ until the end of the string $. If the string contains only letters and numbers, this method returns true. You can set the upper limit. matches a period rather than a range of characters \s matches whitespace (spaces and tabs) Apr 11, 2016 · Keeping the first letter in upper case this would be the regex. I would like to have a regular expression that checks if a string contains only alphanumeric and hyphen. You just have to change the regexp to this : "^[a-zA-Z0-9\-]+$". Feb 28, 2013 · 7. Dec 19, 2012 · Testing for letters, numbers or underscore can be done with \w which shortens your expression: var pattern = /^[\w&. edited May 30, 2014 at 11:52. Could you clarify? Oct 29, 2014 · I'm trying to use HTML5 patterns to validate an input, but I can't get to validate an input with only letters, numbers and spaces between 5 and 40 characters. -]+$/ As mentioned in the comment from Nathan, if you're not using the results from . This code will only check if the last typed character is in the allowed list, you might also want to check if after a paste in your field, the value is still May 13, 2020 · Details. (I replaced your [a-zA-Z] by the Unicode code property for letters \p{L}). asked Feb 4, 2015 at 21:41. To accept one or more digits, change the * to +. )? And disallow when a string contains otherwise (like alphabets or other special characters not listed above). Otherwise people won’t use it. It's Unicode-aware so it'll match letters with umlauts and such (better than trying to roll your own character class like [A-Za-z0-9_] which would only match English letters). NET, Rust. The OTHER problem is using spaces for column separators and within fields without some kind of quoting, but this works for your data. " Jquery validation for Full Name using regular expression. By the end, you will be able to use this regular Dec 20, 2012 · I wouldn't consider a string with 0 occurrences of numeric values/spaces a string consisting of numeric values/spaces. 9 and I would like to validate a string that can have only characters (not special characters - case insensitive), blank spaces and numbers. The Collect Android app and Enketo behave differently with their handling of regex expressions. Regular Expression: Allow letters, numbers, and spaces (with at Sep 20, 2012 · If the question was whether the string contains only letters (and spaces, as we found out later) - then the faester's answer is the right one. Concat(textBox1. -]+$" will suffice in C#. e. In this guide, we will learn how to create a regular expression that allows only letters (uppercase or lowercase) and spaces in a string. For a non-REGEX solution you can use char. This is my regular expression for alphanumeric validation only: var numericReg = /^([a-zA-Z0-9]){1,20}$/; To which, I need to include hyphen and space too. IsLetter Method. answered Oct 6, 2012 at 15:50. Example: Allowed. This String would become 2018 STR Summer Intern Training <<China Power - Towards…. I want Regular Expression to accept only Arabic characters, Spaces and Numbers. This still contains the EBHP. I also changed the 2nd column which had an extra . \d Digit. Something like this ^ [a-zA-Z0-9]+$ gets letters and numbers but I need one for the above. I need to write regular expression which checks the following: Only letters and spaces are allowed not numbers and special charactes The first character should be a valid letter [a-zA-Z] not a space. Oct 18, 2015 · What should be the Regex to allow a string that contains only numbers (0-9) or dashes (-) or dots (. May 3, 2016 · I'm currently using this regex (/^[A-Za-z0-9 _]*[A-Za-z0-9][A-Za-z0-9 _]*$/) to accept letters, numbers, spaces and underscores. However, if you want to allow proper numbers, better go with something like this: or simply use . /\d+\s[a-zA-Z0-9]+/gi. answered May 4, 2018 at 14:30. Regex. If you need more information on a specific topic, please follow the link on the corresponding heading to access the full article or head to the guide. Aug 16, 2016 · I don't think so, he want's to find fields composed of only spaces, so I wrote a check to find it. Note that this Feb 6, 2016 · 1. Jul 10, 2013 · This regex will match all unicode letters and spaces, which may be more than you need, so if you just need English / basic Roman letters, the first regex will be simpler and faster to execute. I want to replace numbers/special chars/white space with empty char, i see there is function named regexp_replace but how to use not much user friendly help avaialble for example i want to use following string. SO I always go with op's way. Disallowed. Sep 8, 2014 · 33. &quot;123456789101236 \\n 123456789101237 \\n Apr 8, 2017 · You don't want to keep all letters, you just want to keep A-Z, a-z and 0-9: gsub("[^A-Za-z0-9 ]","",sample_string) #> [1] " Sample 2 string here EBHP". I agree :) To make things short : - ^ defines the beginning of the string to check and $ defines the end - \s is a space character, \d any numerical character and \w any "literal" character - To check if the word is a letter or a number, check if it respects the pattern [a-zA-Z0-9] (either a lowercase or uppercase letter, or a number) - You can check if it is a succession of the same pattern Nov 3, 2014 · In your question, you say you only want to allow letters A-z, numbers 0-9 and space. This page provides an overall cheat sheet of all the capabilities of RegExp syntax by aggregating the content of the articles in the RegExp guide. This accepts any number of digits, including none. You could also supply a length range {2,3} instead of the one or more + matcher, if that were more appropriate. Jun 13, 2013 · As a rule, I tend to avoid simply a white space in the regex preg_match only letters, numbers and spaces (including umlauts and similar) 1. Feb 1, 2014 · Regular Expression: Allow letters, numbers, and spaces (with at least one letter not number) 0 how to test a string that contains only letter characters and dash(-) [javascript] May 5, 2014 · With /^[a-zA-Z]/ you only check the first character: ^: Assert position at the beginning of the string [a-zA-Z]: Match a single character present in the list below: a-z: A character in the range between "a" and "z" A-Z: A character in the range between "A" and "Z" If you want to check if all characters are letters, use this instead: Jun 25, 2014 · I'm trying to use a regex for testing for only letters and spaces allowed in an input field. Of course the user can enter only letters or only numbers or letters and numbers but not other characters. Where(char. ^ - string must start here. Char. Need to allow user to enter only Numbers or alphabets or spaces or hyphens OR combination of any of the above. Name allow alphabets only,not allow any special characters. join()` takes the filtered list and joins it to a string. John Woo. regular expression for number and spaces in the end. I need a Regex For Numbers, Letters, Spaces and Hyphens Only. And I have exactly the same requirement. I want to change it like this that it takes the combination of number and the character but not only the number. if I post the above, some would come and tell that \w would match also some extra chars other than A-Za-z0-9_ does. So it can have alphabetic characters, numeric characters, spaces, and hypens/underscores/any other key. Regex: ^[A-Z][a-z]{1,15}$ Explanation: [A-Z] matches first upper case letter. regex101: Only letters without numbers Regular Expressions 101 Dec 12, 2014 · Regex to 'dissallow special symbols or spaces', but 'allow numbers and 'uppercase' OR 'lowercase' letters' 3 regular expression to only allow numbers, numbers with dot, & and space Feb 20, 2015 · Same thing with [^[:alnum:]] to leave only letters and numbers -- far faster than any external tool when you're working with shell variables. IsLetter); This would give false result for digits and \/<>*() etc. test(str); console. You can indeed match all those characters, but it's safer to escape the - so that it is clear that it be taken literally. Well, there is an issue in that -, is being interpreted as a range, like a-z, allowing all characters from space to comma. This will match a letter an any letters or numbers which might follow. The program states "Enter a regular expression which entered text must match (evaluated with preg_match, using s and i flags) for it to be valid. test() which returns a simple boolean: May 4, 2018 · To match only a whitespace or a digit you could use: ^[ 0-9]+$. Regex For Numbers, Letters, Spaces and Hyphens Only. If you want to keep those as well, you would need to make a regex like so: Mar 2, 2018 · I got a reference from the link: Javascript validation to allow only Alpha characters, hyphen (-), dot (. 4. Jun 26, 2009 · Regular expression for allowing a user to enter alphanumeric characters and only one non-alphanumeric character 4 Regex to validate length of alphanumeric string Jul 29, 2021 · I want to use regex in kotlin to allow only this kind of strings each strings is length of 15 and can be of any long I just kept 3 numbers as example. return /^[A-Za-z0-9]*$/ . Oct 4, 2023 · Regular expression syntax cheat sheet. ^ - start of string. Mar 16, 2017 · I've tried a lot of different ways, but I think the only one that I can get working will be to remove every character that is not a number, letter or space using regular expressions and gsub (). Jan 8, 2020 · Some regex engines don't support this Unicode syntax but allow the \w alphanumeric shorthand to also match non-ASCII characters. The ^ at the beginning means "match the beginning of the string here", and the Apr 23, 2020 · The [^/] matches any char, not just a digit. If you want to allow only alphabets - hence try. Can anyone help and build a regex for me? The translate approach seems best in most cases, dramatically so with long valid strings, but is beaten out by regexes in test_long_invalid (Presumably because the regex can bail out immediately, but translate always has to scan the whole string). Some special characters need to be escaped, some don't. The only thing I don't want it to have is spaces at the beginning, before you enter any key. I do not know exactly what your requirements are, however, ü is a valid letter in some languages. test () method to check if the string contains only letters and numbers. ay xh bl io ae gr kt hq ut sz