Regular expression to check multiple phone number with and without extensions - angularjs

In my angular application, I've a text field to get phone number from user.
User can enter multiple phone numbers
separated by comma (Without country code and omitting 0 of city code)
For example if the phone number is 042-1234567, User will enter 421234567 and multiple numbers will be like
421234567,421234568,...
This regular expression working perfectly fine for me
^((\d{9})(,\d{9})*)$
But there's exception that user can also add extensions with phone number like this
123456786~19, 123456784~46,..
I've tried following Regx and its working fine for these kind of inputs
^((\d{9}~\d{2})(,\d{9}~\d{2})*)$
But I've to use both of these in one single field so I tried to add OR option and made Regx like this
((\d{9}~\d{2})(,\d{9}~\d{2})*)|((\d{9})(,\d{9})*)
But its not working for both kind of inputs. e.g;
Its not validating this 123456789~12,123456789~12,123456789,123456789~12
Any kind of help will be appreciated.

You may use optional groups:
^\d{9}(?:~\d{2})?(?:,\d{9}(?:~\d{2})?)*$
^^^^^^^^^^^ ^^^^^^^^^^^
See the regex demo
Details
^ - start of string
\d{9} - any 9 digits
(?:~\d{2})? - an optional non-capturing group matching
~ - a tilde
\d{2} - any 2 digits
(?:,\d{9}(?:~\d{2})?)* - zero or more sequences of:
, - a comma
\d{9}(?:~\d{2})? - see above
$ - end of string.
Note that if you need the pattern to also match an empty string, just enclose the pattern with an optional non-capturing group, ^(?:\d{9}(?:~\d{2})?(?:,\d{9}(?:~\d{2})?)*)?$.

Related

SQL Server Dynamic Where Clause - combination of wildcard, multiple values or 1 value

I created a stored proc with a parameter (#iParam) where user will enter up to a maximum 10 "values". The "values" that user will enter will be a combination and/or ALL of the three types:
Using Wild Card - i.e. ABC%
Multiple Exact Values - i.e. BIRD, CAT, DOG
1 Exact Value - i.e. WOLF
The question now is, in my WHERE clause, how do I make it dynamic to switch and/or use the LIKE, =, IN operator depending on user's entered "values"? i.e:
Using Wild Card - WHERE clause will need to use LIKE operator
Multiple Exact Values - WHERE clause will need to use IN operator
1 Exact Value - WHERE clause just need to use = operator
Example 1: If user were to input '%TEXT%' and USA as the values, the WHERE clause needs to know that it'll use LIKE and = operator
Example 2: If user were to input 'STRING%', JOHN, JANE, MARY as the values, the WHERE clause needs to know that it'll use LIKE and IN operator
Example 3: If user were to input SNOOPY, DOG as the values, the WHERE clause needs to know that it'll use IN operator

Regex time field validation fails in ReactJS

I am following this question's solution to validate a Django's TimeField object 06:00:00
in reactjs. The validation fails with the error "Checkin Time" with value "06:00:00" fails to match the required pattern: /^([0-9]{2})\:([0-9]{2})$/ What could be wrong with this regex.
This is my Joi schema. Kindly assist
schema = {
checkin: Joi.string()
.regex(/^([0-9]{2})\:([0-9]{2})$/)
.label("Checkin Time"),
checkout: Joi.string()
.regex(/^([0-9]{2})\:([0-9]{2})$/)
.label("Checkout Time"),
};
The problem is caused by the ^ and $ characters in your regex. They denote the start and end of your string to compare. You basically are saying the value must be exactly two sets of two digit numbers, separated by a colon. However, your example includes seconds (three sets of two digit numbers, separated by colons). In order to support that, while leaving the seconds portion optional, you can do something like this:
/^([0-9]{2}):([0-9]{2})(:[0-9]{2})?$/
We basically create another capture group containing the colon and the seconds portion, and make it optional (? matches 0 or 1 instance of the pattern)

Regex for US Zip code - but make it optional

I need a regex for US zip codes. I've found lots of examples but none that allow for the zip code to also be optional. You see, I am using this on a non-required input field so the valid scenarios are a 5 digit zip code, a 5+4 digit zip code, or no zip code at all. Here is what I have so far but it does not work for the "no zip code at all" scenario:
^(\d{5}(?:\-\d{4})?)$
You need to enclose the whole pattern with a non-capturing optional group:
^(?:\d{5}(?:-\d{4})?)?$
^^^ ^^
See the regex demo
Details:
^ - start of string
(?: - start of the optional group
\d{5} - 5 digits
(?:-\d{4})? - optional group matching - and 4 digits
)? - end of the outer optional group
$ - end of string.
Note that it is the ? quantifier that makes the outer non-capturing group optional (match 1 or 0 times).
You might as well use capturing groups if you want to make your pattern shorter, but it a non-capturing one is more natural to use here since you are not interested in captured subvalues.

Matching Regular Expressions In SQL Server

I am trying to extract id of Android app from its url but getting extra characters.
Using replace function in sql server, below are two sample urls:
https://play.google.com/store/apps/details?id=com.flipkart.android&hl=en com.flipkart.android
https://play.google.com/store/apps/details?hl=en_US&id=com.surveysampling.mobile.quickthoughts&referrer=mat_click_id%3Df1901cef59f79b1542d05a1fdfa67202-20150429-5128 en_US&id=com.surveysampling.mobile.quickthoughts&r
I am doing this right now:
SELECT
SUBSTRING(REPLACE(PREVIEW, '&hl=en',''), CHARINDEX('?', PREVIEW) + 4 , 50)
FROM OFFERS_TABLE;
But for 1st I am getting com.flipkart.android which is correct, but for 2nd I am getting en_US&id=com.surveysampling.mobile.quickthoughts&r.
I want to remove en_US&id from starting of it and &r from its end.
Can someone help me with any post or url from where I can refer?
What you are actually trying to do is extract the string preceded by id= until the & is found which is separator for variables in URL. Taking this condition I came up with following regex.
Regex: (?<=id=)[^&]*
Explanation: It uses the lookbehind assertion that is the string is preceded by id= until the first & is found.
Regex101 Demo
It seems like you've made some assumptions of lengths. The the &r is appearing because that is 50 characters. You are also getting the en_US because you assumed 4 characters at the beginning but your second string has more. Perhaps you can split on & and then look for the variable that begins with id=.
it seems like a function like this would help.
http://www.sqlservercentral.com/blogs/querying-microsoft-sql-server/2013/09/19/how-to-split-a-string-by-delimited-char-in-sql-server/

Tdbf/tdataset sorting multiple fields in delphi

I have a delphi application that uses tdbf which is based on tdataset with the advantage of not requiring bde engine. I needed the table to be sorted and I did this one a single field by adding an indexdef and then specifying the indexfieldnames.
I am trying to now get it to sort on 2 fields ie group men together and then women together and then have each group sorted on salary so that we see females from lowest earner to highest earner followed by men in the same way.
I have read every piece of material stating that you simply specify sortfield of the indexdef as 'gender+salary'. When I try use the index I get told that '+' is not a valid fieldname. I have tried every delimeter from '.'. ','. '&' and ';'. Every delimeter gets picked up as a field that doesn't exist. What is the correct way to sort a table on multiple fields?
Thanks in advance
Clinton Brits
xBASE (dBASE and it's derivatives) requires that fields in an index all be converted to the same data type, typically strings. To do that typically requires some common functions:
DTOS() - Converts an xBASE date to the format CCYYMMDD as a string
STR() - Converts a numeric to a string, with an optional width specifier (default 10) and number of digits to the right of the decimal point. Specifically, the syntax is specified as STR(<numeric> [, <width> [, <decimaldigits>] ]).
SUBSTR() - Extracts a portion of a string from another, with a specified starting position and number of characters
IIF() - Immediate IF, used to convert logicals (eg., IIF(Married = .T., 'Y', 'N')
Index expressions are indeed combined with the + operator. The error you're receiving is probably because you haven't converted to a common data type.
As you've specified the Gender column (probably defined as CHAR 1) and Salary column (probably a NUMERIC of some size), you can use something like
Dbf1.AddIndex('GENDER_SAL', 'GENDER + STR(SALARY, 10, 0)', []);
This creates a index on an expression like F 10000, F 200000, M 12000, where SALARY is converted to the default width of 10 characters (left padded with spaces) and no decimal digits. This should work for you.
I have not used the component, but it looks like they want to use index expressions that are similar to what we used to use in dBase III. On page 7 in the PDF version of the documentation, they offer an example under the Expressions topic:
Dbf1. AddIndex('INDEX1 ', 'DTOS( DATEFIELD)+ SUBSTR ( LONGFIELD ,1 ,10)+ SUBSTR
( LONGFIELD2 ,1 ,20)', []);
You could try their SubStr function on your fields with parameters that would include the whole string and see if that at least gets you a result.

Resources