numbers

PHP: Simple regular expressions to match length?

拜拜、爱过 提交于 2020-01-02 01:02:33
问题 I'm creating a registration system that needs to check the name/pass etc. with REGEX (and prefer to), what I've got so far is: //Check so numbers aren't first, such as 00foobar preg_match('/^(?!\d)[a-z0-9]+$/iD',$usrname); //Just simple check preg_match('/^[a-zA-Z0-9]+$/',$psword); But I have to do stupid things in IF statements like: if strlen($psword) > 30 || if (strlen($psword) < 4) .... How would I impliment the length checking in my two original regular expression statements? This would

Rails 3 change default english numbers to arabic numbers

浪子不回头ぞ 提交于 2020-01-01 19:48:06
问题 I want to change the default numbers from english to arabic when the user switches to the arabic interface. 13 => ١٣ 89 => ٨٩ What is the best way to tackle this problem? 回答1: I add in helper module ARABIC_NUMBERS = %w(٠ ١ ٢ ٣ ٤ ٥ ٦ ٧ ٨ ٩) def ta numbers numbers = numbers.to_s if numbers.is_a? Integer results = numbers.chars.map { |char| ARABIC_NUMBERS[char.to_i] }.join end 回答2: Check this code : https://github.com/gdotdesign/rails-arabic-convert/blob/master/app/helpers/convert_helper.rb. It

How to find the value closest to zero using SQL Server

 ̄綄美尐妖づ 提交于 2020-01-01 16:31:28
问题 Let's say I have a table that could have various numbers in it, for example it could look like the following: ExampleA: MyTable -10, -3, 5, 10, ExampleB: MyTable -10, -5, 3, 10, So if I queried the table in ExampleA I'd want it to return "-3" (The value closet to 0) Likewise if I queried the table in ExampleB I'd want it to return "3" (The value closest to 0) I always want to find the value that is closest to zero regardless of the numbers in the table, how can I do this? Also, how could I

1: command not found

不问归期 提交于 2020-01-01 15:36:13
问题 I'm writing a divides-by-three function in Bash, and it won't let me set a variable to a number. fizzy.sh: #!/usr/bin/env sh div3() { return `$1 % 3 -eq 0` } d=div3 1 echo $d Example: $ ./fizzy.sh ./fizzy.sh: line 7: 1: command not found 回答1: Bash functions normally "return" values by printing them to standard output, where the caller can capture them using `func args ...` or $(func args ...) This makes functions work like external commands. The return statement, on the other hand, sets the

Python - find integer closest to 0 in list [duplicate]

↘锁芯ラ 提交于 2020-01-01 09:23:18
问题 This question already has answers here : Closed 7 years ago . Possible Duplicate: finding index of an item closest to the value in a list that's not entirely sorted I've got a list of positive and negative numbers in Python ( [237, 72, -18, 237, 236, 237, 60, -158, -273, -78, 492, 243] ). I want to find the number which is closest to 0. How do I do this? 回答1: How about this: lst = [237, 72, -18, 237, 236, 237, 60, -158, -273, -78, 492, 243] min((abs(x), x) for x in lst)[1] A nice and much

REGEX To accept numbers separated by commas, but number range is 0-32767

我的未来我决定 提交于 2020-01-01 08:47:36
问题 I need to write a regular expression for taking input like this 23,456,22,1,32767 i.e. No commas allowed at the start or end. Spaces may come before and/or start of comma for e.g. 23, 45,56 ,67 etc. Ranges of each number should be 0-32767. Currently I am using regular expression like this [0-9]+(,[0-9]+)* . This allows for numbers separated by commas only ( not allowing spaces at all), and it does not check for the range of number. 回答1: It's probably wise to do it in two steps. First check

How do I convert a positive number to negative in Delphi?

你。 提交于 2020-01-01 08:45:29
问题 How do I convert a positive Integer to a negative with Delphi? I know you could use ABS(int) to convert a negative to a positive, but I need it to convert positive to negative. 回答1: from what I know there is no function for that. you can make if yourvariable > 0 then yourvariable := -yourvariable; 回答2: If you want to be absolutely sure to get a negative result (or zero), use number := -abs(number) 回答3: Ehhh... Too late but number := number * -1; would work too, but this change the symbol of

How do I convert a positive number to negative in Delphi?

北城以北 提交于 2020-01-01 08:45:07
问题 How do I convert a positive Integer to a negative with Delphi? I know you could use ABS(int) to convert a negative to a positive, but I need it to convert positive to negative. 回答1: from what I know there is no function for that. you can make if yourvariable > 0 then yourvariable := -yourvariable; 回答2: If you want to be absolutely sure to get a negative result (or zero), use number := -abs(number) 回答3: Ehhh... Too late but number := number * -1; would work too, but this change the symbol of

How to convert numbers to words in Erlang?

你说的曾经没有我的故事 提交于 2020-01-01 06:56:13
问题 I found this interesting question about converting numbers into "words": Code Golf: Number to Words I would really like to see how you would implement this efficiently in Erlang. 回答1: -module(int2txt). -export([convert/1]). convert(0) -> "zero"; convert(N) -> convert1(N). convert1(0) -> ""; convert1(N) when N>=1000 -> join(convert_thou(thoubit(N), 0),convert1(N rem 1000)); convert1(N) when N>=100 -> join(convert1(N div 100),"hundred",convert1(N rem 100)); convert1(N) when N>=20 -> join(tens(

How restrict textbox in C# to only receive numbers and (dot “.” or comma “,”), after “.” or “,” only allow 2 number characters

大憨熊 提交于 2020-01-01 06:55:09
问题 i am trying develop a code to restrict TextBox using C# to only allow numbers entry + comma(",") or dot(".") + only 2 numbers after dot or comma So this way see possible numbers that can entry: 3213,04 = OK 3211,664 = Not 32.31 = OK 32.3214 = Not 334,,00 = Not 3247,.00 = Not 214.,00 = Not 32.. = Not 8465,0 = Ok 654.0 = Ok Understood My goal ? I developed code bellow private void txtValormetrocubico_KeyPress(object sender, KeyPressEventArgs e) { if (txtValormetrocubico.TextLength >= 0 && (e