Contraints on dijit.form.ValidationTextBox - dojo

How to specify length constraint of min and max digits on dijit.form.ValidationTextBox programmatically ?
Thanks

I recommend you to use the 'pattern' option which used regex to manage min and max:
eb = new ValidationTextBox({
value: 2,
pattern: '[\\w]{2,4}'
});
I will explain the pattern: [\\w]{2,4}.
\w: accept letters only.
{2,4}: define min and max letters that are allowed. min is 2 and max is 4.
If you want to unlimit the max, leave it empty like this: {2,}.
You can add \\d AS numbers only or combine then with letters like this: \\w\\d

Related

Best way to count words in a string on SQL impala/Hive

I need to count words in a string, with SQL Impala/Hive. What is the best way?
In Oracle I use regexp_count() function, like the example below:
SELECT regexp_count('1aa 2bb 3cc', '\s*[a-z]+\s*'); -- result: 3
In impala/hive we can't use the above function. Which is the best way to achieve this goal?
Thank in advance
can you simply use this formula - count of words = count of spaces +1.
so calculate total length and then length of all spaces removed or replaced by empty string. Minus first from second and you will get number of spaces.
Add 1 to it.
select length('1aa 2bb 3cc') - length(replace('1aa 2bb 3cc',' ',''))+1
Simply, you can do it with split and size function which returns the length of the split array.
SELECT size(split('1aa 2bb 3cc', ' ')); -- result: 3

Use regexp inSQL/PL for no repetitions in digits

I have a table below and need to use a regular expression to display the correct course digits ( 3 digits being the max # of digits) and also max sure no number appears twice.
the following code I have created is this:
select regexp_substr(course_number,'([0-9][0-9][0-9])\1') as CourseNumber
from courses
/
this is correct showing me an output of this:
How can I sure the regexp in sql/pl to query the digits with no numbers repeating?
the table I created looks like this:

Extract number between two characters in Hive SQL

The query below outputs 1642575.0. But I only want 1642575 (just the number without the decimal and the zero following it). The number of delimited values in the field varies. The only constant is that there's always only one number with a decimal. I was trying to write a regexp function to extract the number between " and ..
How would I revise my regexp_extract function to get the desired output? Thank you!
select regexp_extract('{"1244644": "1642575.0", "1338410": "1650435"}','([1-9][0-9]*[.][0-9]+)&*');
You can cast the result to bigint.
select cast(regexp_extract('{"1244644": "1642575.9", "1338410": "1650435"}','([1-9][0-9]*[.][0-9]+)&*') as bigint) col;
output - 1642575
You can use round if you want to round it off.
select round(regexp_extract('{"1244644": "1642575.9", "1338410": "1650435"}','([1-9][0-9]*[.][0-9]+)&*')) col;
output - 1642576
Use this regexp: '"(\\d+)\\.' - means double-quote, capturing group with one or more digits, dot.
select regexp_extract('{"1244644": "1642575.9", "1338410": "1650435"}','"(\\d+)\\.',1)
Result:
1642575
To skip any number of leading zeroes, use this regexp: '"0*(\\d+)\\.'

Postgres SQL regexp_replace replace all number

I need some help with the next. I have a field text in SQL, this record a list of times sepparates with '|'. For example
'14613|15474|3832|148|5236|5348|1055|524' Each value is a time in milliseconds. This field could any length, for example is perfect correct '3215|2654' or '4565' (only 1 value). I need get this field and replace all number with -1000 value.
So '14613|15474|3832|148|5236|5348|1055|524' will be '-1000|-1000|-1000|-1000|-1000|-1000|-1000|-1000'
Or '3215|2654' => '-1000|-1000' Or '4565' => '-1000'.
I try use regexp_replace(times_field,'[[:digit:]]','-1000','g') but it replace each digit, not the complete number, so in this example:
'3215|2654' than must be '-1000|-1000', i get:
'-1000-1000-1000-1000|-1000-1000-1000-1000', I try with other combinations and more options of regexp but i'm done.
Please need your help, thanks!!!.
We can try using REGEXP_REPLACE here:
UPDATE yourTable
SET times_field = REGEXP_REPLACE(times_field, '\y[0-9]+\y', '-1000', 'g');
If instead you don't really want to alter your data but rather just view your data this way, then use a select:
SELECT
times_field,
REGEXP_REPLACE(times_field, '\y[0-9]+\y', '-1000', 'g') AS times_field_replace
FROM yourTable;
Note that in either case we pass g as the fourtb parameter to REGEXP_REPLACE to do a global replacement of all pipe separated numbers.
[[:digit:]] - matches a digit [0-9]
+ Quantifier - matches between one and unlimited times, as many times as possible
your regexp must look like
regexp_replace(times_field,'[[:digit:]]+','-1000','g')

Rails Datatypes,length and Datepicker

For an alphanumeric input, what kind of datatype should i use in Rails?
Also how can i edit the length of the input, like Min 5 characters to Max 30 characters. ?
Any help is appreciated.Thank you.
From very little i got your question i guess you want something like following
For an alphanumeric input, what kind of datatype should i use in Rails?
It should be varchar (string)
Also how can i edit the length of the input, like Min 5 characters to Max 30 characters. ?
Ref this
validates :first_name, length: { minimum: 5, maximum: 30 }