I need a regular expression that matches the following - html

I need a regular expression that matches the following to be used on a web page:
-The first number must be a digit
-The length must be a minimum of 10 digits
-No spaces, alpha, special characters allowed

As my understanding, you need to check if it is a number (containing only the digits 0-9) and this number should be minimum of 10 digits.
Then the following code should work:
/^\d{10,}$/

Related

Regex for float(x,y) possible?

In the following, float(x,y) means a number with x total digits and y decimals.
I am trying to do client side validation for an HTML Input field. The field corresponds to a MySQL column with data type float(x,y). I know I can define a pattern like float(5,2) with lots of 'ORs'. Is there an efficient way of generating a Regex for this such that I can encode it in my web document?
Something of a workaround is to specify \d+(\.\d{1,y})? and then set maxlength=x+1. Should be x+1 because the decimal place is counted. This would then allow the submit of an integer of length x+1 contrary to specification. I realize I can do JavaScript validation but I would like to achieve the desired with HTML validation.
You can first check the total length with a lookahead and then check for the length of numbers after the decimal point.
If you want X total number of digits and at most Y decimal points, you can use:
^(?=.{X+1}$)([1-9]\d*|0)\.\d{1,Y}$
Explanation:
^ asserts you are in the start position of the line
(?= lookahead (zero length) match for:
.{X + 1} X+1 characters
$ end of line //now you have asserted the total length
the whole part either
0 is a single zero
[1-9]\d* more than a single digit and does not start with zero
\. a dot for the decimal point
\d{1,Y} at least 1 and at most Y digits
$ asserts end of line
Note that you do not need to check the length of the whole part since you are already checking for the total length and the length of digits after the decimal so the part before the decimal point is automatically correct.
Example:
For X = 5 and Y = 2, you will have:
^(?=.{8}$)([1-9]\d*|0)\.\d{1,2}$
Regex101 demo

I want to prevent a textbox to accept only alphabets

I am designing a membership form and want only alphabets is textbox as username.
ng-pattern="/^\d{1,10}$/"
I tried it but it not works.
The pattern you're using will only get digits
/^\d{1,10}$/"
\d{1,10} matches a digit (equal to [0-9])
{1,10} Quantifier — Matches
between 1 and 10 times, as many times as possible, giving back as
needed
$ asserts position at the end of a line
If you want only alphanumeric characters try this:
/^[a-zA-Z]*$
It will accept any character a through z -- capital or lower case.

Filtering phone numbers REGEXP

I have a MySQL query to find 10 digit phone numbers that start with +1
SELECT blah
FROM table
WHERE phone REGEXP'^\\+[1]{1}[0-9]{10}$'
How can I filter this REGEXP further to only search certain 3 digit area codes? (ie. International 10 digit phone numbers who share US number format)
I tried using the IN clause ie. IN('+1809%','+1416%') but ended up with error in syntax
WHERE phone REGEXP'^\\+[1]{1}[0-9]{10}$' IN('+1809%','+1416%')
You may use a grouping construct with an alternation operator here, like
REGEXP '^\\+1(809|416)[0-9]{7}$'
^^^^^^^^^
Just subtract 3 from 10 to match the trailing digits. Note that in MySQL versions prior to 8.x, you cannot use non-capturing groups, you may only use capturing ones.
Also, [1]{1} pattern is equal to 1 because each pattern is matched exactly once by default (i.e. {1} is always redundant) and it makes littel sense to use a character class [...] with just one single symbol inside, it is meant for two or more, or to avoid escaping some symbols, but 1 does not have to be escaped as it is a word char, so the square brackets are totally redundant here.

What is the Regex to match a string (only alphabets of maximum length 20 and minimum 1) followed by : and a six digit number.

My regular expression should match the strings of following formats.
a:123456, sdfsdf:765756, dskjsdkfjh: 200000 etc.
[a-zA-Z]{1,20}:\d{6}
You can try this.

Regarding TCL format command

% format %2s 100
100
% format %.2s 100
10
%
%
% format %0.2s 100
10
%
I am not able to understand the difference between %2s and %.2s .
Can anyone explain me ?
TCL format command manual page specifies that format string can consist of six different parts. In this case second, third and fourth portions are of interest.
If there is a character from set [-+ 0#], they specify justification of the field, if there should be padding, sign shown of numbers, etc. 0 in the third example specifies that number should be padded with zeros instead of spaces. However, in this example there is nothing to pad.
If there is some other number without dot (2 in the first example), the number is interpreted as minimum field length and number is padded with spaces if necessary.
If there is a dot, the number after if interpreted as precision indicator and way it behaves differs depending on the other format parameters. For strings it means the maximum number of characters.
With
format %4.2s foo
you then get
fo
That is, at most two characters are printed, but the field width is at minimum 4 characters.
If you are actually trying to print a number instead of string, then the sixth (the only mandatory) field is important. "s" means "print as is". For numbers you want to use for example "d" which means decimal (integer) or "f" for floating point. Check the manual for the whole list.
With
format %4.2d 100 # Print with at least two numbers and with field width of 4 characters
you get
100
With
format %08.2f 123.45678 # Field width 8, pad with zeros, print two decimals
you get
00123.46
In the last example notice that all numbers and the dot are counted for the field length and that the number has been rounded.