This question already has an answer here:
How to use regex validator for phone numbers like 999-999-9999
(1 answer)
Closed 4 years ago.
I want to create a regex for this pattern 999-999-9999, please advise.
<input type='tel' pattern='/^\(?(\d{3})\)?[- ]?(\d{3})[- ]?(\d{4})$/' title='Phone Number (Format: 999-999-9999)' />
You nearly had it. Here's a simple one.
It goes: 3 digits, hyphen, 3 digits, hyphen, 4 digits. But that's pretty self explanatory.
\d{3}-\d{3}-\d{4}
Related
This question already has an answer here:
Reference - What does this regex mean?
(1 answer)
Closed 2 years ago.
For example, I would like to find ty in:
erytypotym5ty
etytyty
koetymitywty
or il in:
keililmil
ilwrilltyil5ile
^.*(\w{2}).*\1.*\1.*$.
The two letters (also digits and _; you could replace \w with [a-zA-Z], if you don't want them) will be in group 1.
https://regex101.com/r/11Oq70/1
This question already has an answer here:
Validating credit card format using regular expressions?
(1 answer)
Closed 3 years ago.
How to add a condition where if the first character is 4 then 16 digits and if 3 then 15 digits?
this is what i tried so far:
<ion-input
ngModel name="CNumber"
required
(ionChange)="C_number($event.target.value)"
(ionInput)="C_number($event.target.value)"
maxlength="{{Maxlength}}"
type="tel"
pattern="^(4)[0-9]{15}$"
>
^(4)[0-9]{15}
this will accept if the first is 4 and allows 16 characters, but how to add starting digit 3 and when so it accepts 15 characters only?
I'd try simple.alternative:
^((4)[0-9]{15})|((3)[0-9]{14})$
This question already has answers here:
How can I match "anything up until this sequence of characters" in a regular expression?
(15 answers)
Closed 3 years ago.
I have strings that are concatenations of airline codes/flightnumbers, separated with ;. The airline code and flight number are either separated by a space or -. So some examples are:
AA-1234;UA 243;EK 23;
9W 23;B6-134
Now I want to grab the airline codes from this.
I came up with the following regex: [a-zA-Z0-9]{2}[ -]. This works to grab the airline codes but also includes the airlinecode-flightnumber separator. How would I adjust my regex to not include this?
[a-zA-Z0-9]{2}(?=[ -])
See it in action here
This question already has answers here:
HTML input for Positive Whole Numbers Only (Type=number)
(10 answers)
jQuery: what is the best way to restrict "number"-only input for textboxes? (allow decimal points)
(40 answers)
Closed 5 years ago.
My code is very simple:
<input id="myID" type="number" pattern="^\d*$">
Based on a famous online regex test website, it should only let me write numbers, like 1 and 123, but not strings like 1a and 2e.
Instead it lets me write the letter "e". I guess it's for scientific notation? I don't need it. I just need integer numbers. How can I do this?
I've also tried ^[0-9]*$ but it still lets me write the letter "e". This happens on Chrome.
JSFiddle
This question already has answers here:
Regex to match only letters
(20 answers)
Closed 9 years ago.
I was looking for a regex that can validate phone numbers, but somehow i cannot find a universal solution.
So i just want to check if the string has any alphabets that is a-z
If it does not then pass it, for example
000 -> Pass
000(1) -> Pass
000a -> Fail
(?mx)^(?=.*?([0-9]))((?![a-zA-Z]).)*$
This will check to see if your line has any numbers in it while NOT having any alpha chars. See the example here.
its for phone numbers validation
RegExp(/^[0-9 +()-]{3,30}$/i)
for only string
RegExp(/^[a-zA-Z]{1,2}$/i)