alphanumeric

Regex for checking if a string is strictly alphanumeric

做~自己de王妃 提交于 2019-11-27 13:00:45
How can I check if a string contains only numbers and alphabets ie. is alphanumeric? Raghav Considering you want to check for ASCII Alphanumeric characters, Try this: "^[a-zA-Z0-9]*$" . Use this RegEx in String.matches(Regex) , it will return true if the string is alphanumeric, else it will return false. public boolean isAlphaNumeric(String s){ String pattern= "^[a-zA-Z0-9]*$"; return s.matches(pattern); } If it will help, read this for more details about regex: http://www.vogella.com/articles/JavaRegularExpressions/article.html In order to be unicode compatible: ^[\pL\pN]+$ where \pL stands

only allow English characters and numbers for text input

生来就可爱ヽ(ⅴ<●) 提交于 2019-11-27 11:36:32
问题 Live Demo: http://jsfiddle.net/thisizmonster/DveuB/ How can I change this so that the input only allows the characters A-Z, a-z, 0-9 while typing, without using a regular expression? 回答1: Assuming you also want to accept spaces: $("#user").keypress(function(event){ var ew = event.which; if(ew == 32) return true; if(48 <= ew && ew <= 57) return true; if(65 <= ew && ew <= 90) return true; if(97 <= ew && ew <= 122) return true; return false; }); If you don't want to accept spaces then remove the

Sorting strings with numbers in Bash [duplicate]

喜你入骨 提交于 2019-11-27 07:03:01
This question already has an answer here: How to sort strings that contain a common prefix and suffix numerically from Bash? 4 answers I've often wanted to sort strings with numbers in them so that, when sorting e.g. abc_2, abc_1, abc_10 the result is abc_1, abc_2, abc_10 . Every sort mechanism I've seen sorts as abc_1, abc_10, abc_2 , that is character by character from the left. Is there any efficient way to sort to get the result I want? The idea of looking at every character, determining if it's a numeral, building a substring out of subsequent numerals and sorting on that as a number is

How to strip all non alphanumeric characters from a string in c++?

北城余情 提交于 2019-11-27 03:58:42
I am writing a piece of software, and It require me to handle data I get from a webpage with libcurl. When I get the data, for some reason it has extra line breaks in it. I need to figure out a way to only allow letters, numbers, and spaces. And remove everything else, including line breaks. Is there any easy way to do this? Thanks. Write a function that takes a char and returns true if you want to remove that character or false if you want to keep it: bool my_predicate(char c); Then use the std::remove_if algorithm to remove the unwanted characters from the string: std::string s = "my data";

Allow only alphanumeric in textbox

一世执手 提交于 2019-11-27 03:50:51
问题 I have a textbox that should disallow entering any special characters. The user can enter : A-Z a-z 0-9 Space How can I make the KeyDown event to do this? 回答1: private void _txtPath_KeyDown(object sender, KeyEventArgs e) { if ((e.Key < Key.A) || (e.Key > Key.Z)) e.Handled = true; } 回答2: Handling the KeyDown or KeyPress events is one way to do this, but programmers usually forget that a user can still copy-and-paste invalid text into the textbox. A somewhat better way is to handle the

How to check if a string only contains alphanumeric characters in objective C?

这一生的挚爱 提交于 2019-11-27 00:16:45
问题 I'm working on a small iphone project and i would need to check if the userName entered only contains alphanumerical characters? (A-Z, a-z, 0-9 . How would i go about checking it? 回答1: If you don't want to bring in a regex library for this one task... NSString *str = @"aA09"; NSCharacterSet *alphaSet = [NSCharacterSet alphanumericCharacterSet]; BOOL valid = [[str stringByTrimmingCharactersInSet:alphaSet] isEqualToString:@""]; 回答2: This will work: @implementation NSString (alphaOnly) - (BOOL)

Determine if char is a num or letter

一个人想着一个人 提交于 2019-11-26 20:15:50
How do I determine if a char in C such as a or 9 is a number or a letter? Is it better to use: int a = Asc(theChar); or this? int a = (int)theChar You'll want to use the isalpha() and isdigit() standard functions in <ctype.h> . char c = 'a'; // or whatever if (isalpha(c)) { puts("it's a letter"); } else if (isdigit(c)) { puts("it's a digit"); } else { puts("something else?"); } chars are just integers, so you can actually do a straight comparison of your character against literals: if( c >= '0' && c <= '9' ){ This applies to all characters. See your ascii table . ctype.h also provides

converting a number base 10 to base 62 (a-zA-Z0-9)

安稳与你 提交于 2019-11-26 20:09:02
I have a number in base 10. Is there anyway to translate it to a base 62? Example: echo convert(12324324); // returns Yg3 (fantasy example here) PHP's base_convert() can convert up to base 36. Eineki OLD : A quick and dirty solution can be to use a function like this: function toChars($number) { $res = base_convert($number, 10,26); $res = strtr($res,'0123456789','qrstuvxwyz'); return $res; } The base convert translate your number to a base where the digits are 0-9a-p then you get rid of the remaining digits with a quick char substitution. As you may observe, the function is easily reversible.

How to determine if a String has non-alphanumeric characters?

我是研究僧i 提交于 2019-11-26 18:38:16
I need a method that can tell me if a String has non alphanumeric characters. For example if the String is "abcdef?" or "abcdefà", the method must return true. Using Apache Commons Lang: !StringUtils.isAlphanumeric(String) Alternativly iterate over String's characters and check with: !Character.isLetterOrDigit(char) You've still one problem left: Your example string "abcdefà" is alphanumeric, since à is a letter. But I think you want it to be considered non-alphanumeric, right?! So you may want to use regular expression instead: String s = "abcdefà"; Pattern p = Pattern.compile("[^a-zA-Z0-9]")

Regex for checking if a string is strictly alphanumeric

落花浮王杯 提交于 2019-11-26 18:14:30
问题 How can I check if a string contains only numbers and alphabets ie. is alphanumeric? 回答1: Considering you want to check for ASCII Alphanumeric characters, Try this: "^[a-zA-Z0-9]*$" . Use this RegEx in String.matches(Regex) , it will return true if the string is alphanumeric, else it will return false. public boolean isAlphaNumeric(String s){ String pattern= "^[a-zA-Z0-9]*$"; return s.matches(pattern); } If it will help, read this for more details about regex: http://www.vogella.com/articles