alphanumeric

Check if User Inputs a Letter or Number in C

落花浮王杯 提交于 2019-11-26 16:55:20
问题 Is there an easy way to call a C script to see if the user inputs a letter from the English alphabet? I'm thinking something like this: if (variable == a - z) {printf("You entered a letter! You must enter a number!");} else (//do something} I want to check to make sure the user does not enter a letter, but enters a number instead. Wondering if there is an easy way to pull every letter without manually typing in each letter of the alphabet :) 回答1: #include <ctype.h> if (isalpha(variable)) { ..

Regular expression to allow spaces between words

↘锁芯ラ 提交于 2019-11-26 15:44:07
I want a regular expression that prevents symbols and only allows letters and numbers. The regex below works great, but it doesn't allow for spaces between words. ^[a-zA-Z0-9_]*$ For example, when using this regular expression "HelloWorld" is fine, but "Hello World" does not match. How can I tweak it to allow spaces? tl;dr Just add a space in your character class . ^[a-zA-Z0-9_ ]*$ Now, if you want to be strict... The above isn't exactly correct. Due to the fact that * means zero or more , it would match all of the following cases that one would not usually mean to match: An empty string, "".

How to remove all non-alpha numeric characters from a string in MySQL?

╄→尐↘猪︶ㄣ 提交于 2019-11-26 13:28:24
I'm working on a routine that compares strings, but for better efficiency I need to remove all characters that are not letters or numbers. I'm using multiple REPLACE functions now, but maybe there is a faster and nicer solution ? None of these answers worked for me. I had to create my own function called alphanum which stripped the chars for me: DROP FUNCTION IF EXISTS alphanum; DELIMITER | CREATE FUNCTION alphanum( str CHAR(255) ) RETURNS CHAR(255) DETERMINISTIC BEGIN DECLARE i, len SMALLINT DEFAULT 1; DECLARE ret CHAR(255) DEFAULT ''; DECLARE c CHAR(1); SET len = CHAR_LENGTH( str ); REPEAT

Sorting strings with numbers in Bash [duplicate]

陌路散爱 提交于 2019-11-26 12:57:44
问题 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,

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

て烟熏妆下的殇ゞ 提交于 2019-11-26 08:55:29
问题 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. 回答1: 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

Determine if char is a num or letter

送分小仙女□ 提交于 2019-11-26 07:33:17
问题 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 回答1: 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?"); } 回答2: chars are just integers, so you can actually do a straight comparison of your character against literals:

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

纵然是瞬间 提交于 2019-11-26 07:31:12
问题 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. 回答1: 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

How to remove leading zeros from alphanumeric text?

。_饼干妹妹 提交于 2019-11-26 05:55:17
问题 I\'ve seen questions on how to prefix zeros here in SO. But not the other way! Can you guys suggest me how to remove the leading zeros in alphanumeric text? Are there any built-in APIs or do I need to write a method to trim the leading zeros? Example: 01234 converts to 1234 0001234a converts to 1234a 001234-a converts to 1234-a 101234 remains as 101234 2509398 remains as 2509398 123z remains as 123z 000002829839 converts to 2829839 回答1: Regex is the best tool for the job; what it should be

how do i block or restrict special characters from input fields with jquery?

a 夏天 提交于 2019-11-26 05:48:00
问题 How do I block special characters from being typed into an input field with jquery? 回答1: A simple example using a regular expression which you could change to allow/disallow whatever you like. $('input').on('keypress', function (event) { var regex = new RegExp("^[a-zA-Z0-9]+$"); var key = String.fromCharCode(!event.charCode ? event.which : event.charCode); if (!regex.test(key)) { event.preventDefault(); return false; } }); 回答2: I was looking for an answer that restricted input to only

Generate a random alphanumeric string in Cocoa

戏子无情 提交于 2019-11-26 04:58:55
问题 I want to call a method, pass it the length and have it generate a random alphanumeric string. Are there any utility libraries out there that may have a bunch of these types of functions? 回答1: Here's a quick and dirty implementation. Hasn't been tested. NSString *letters = @"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"; -(NSString *) randomStringWithLength: (int) len { NSMutableString *randomString = [NSMutableString stringWithCapacity: len]; for (int i=0; i<len; i++) {