Validate Mobile number using regular expression - regex

I need to validate mobile number. My need:
The number may start with +8801 or 8801 or 01
The next number can be 1 or 5 or 6 or 7 or 8 or 9
Then there have exact 8 digit.
How can i write the regular expression using this conditions ?
the mobile numbers I tried
+8801811419556
01811419556
8801711419556
01611419556
8801511419556

Should be pretty simple:
^(?:\+?88)?01[15-9]\d{8}$
^ - From start of the string
(?:\+?88)? - optional 88, which may begin in +
01 - mandatory 01
[15-9] - "1 or 5 or 6 or 7 or 8 or 9"
\d{8} - 8 digits
$ - end of the string
Working example: http://rubular.com/r/BvnSXDOYF8
Update 2020
As BTRC approved 2 new prefixes, 013 for Grameenphone and 014 for Banglalink, updated expression for now:
^(?:\+?88)?01[13-9]\d{8}$

You may use either one of given regular expression to validate Bangladeshi mobile number.
Solution 1:
/(^(\+88|0088)?(01){1}[56789]{1}(\d){8})$/
Robi, Grameen Phone, Banglalink, Airtel and Teletalk operator mobile no are allowed.
Solution 2:
/(^(\+8801|8801|01|008801))[1|5-9]{1}(\d){8}$/
Citycell, Robi, Grameen Phone, Banglalink, Airtel and Teletalk operator mobile no are allowed.
Allowed mobile number pattern
+8801812598624
008801812598624
01812598624
01712598624
01919598624
01672598624
01512598624
................
.................

Use the following regular expression and test it if you want on following site quickly
regex pal
[8]*01[15-9]\d{8}

I know, that question was asked long time ago, but i assume that #G. M. Nazmul Hossain want to validate mobile number againt chosen country. I show you, how to do it with free library libphonenumber from Google. It's available for Java, C++ and Javascript, but there're also fork for PHP and, i believe, other languages.
+880 tells me that it's country code for Bangladesh. Let's try to validate example numbers with following code in Javascript:
String bdNumberStr = "8801711419556"
PhoneNumberUtil phoneUtil = PhoneNumberUtil.getInstance();
try {
//BD is default country code for Bangladesh (used for number without 880 at the begginning)
PhoneNumber bdNumberProto = phoneUtil.parse(bdNumberStr, "BD");
} catch (NumberParseException e) {
System.err.println("NumberParseException was thrown: " + e.toString());
}
boolean isValid = phoneUtil.isValidNumber(bdNumberProto); // returns true
That code will handle also numbers with spaces in it (for example "880 17 11 41 95 56"), or even with 00880 at the beggininng (+ is sometimes replaced with 00).
Try it out yourself on demo page. Validates all of provided examples and even more.

Have a look at libphonenumber at:
https://code.google.com/p/libphonenumber/

Bangladeshi phone number (Citycell, Robi, Grameen Phone, Banglalink, Airtel and Teletalk operators) validation by using regular expression :
$pattern = '/(^(\+8801|8801|01|008801))[1-9]{1}(\d){8}$/';
$BangladeshiPhoneNo = "+8801840001417";
if(preg_match($pattern, $BangladeshiPhoneNo)){
echo "It is a valid Bangladeshi phone number;
}

**Laravel Bangladeshi Phone No validation for (Citycell, Robi, Grameen Phone, Banglalink, Airtel and Teletalk) and start with +88/88 then 01 then 356789 then 8 digit**
public function rules()
{
return [
'mobile' => 'sometimes|regex:/^(?:\+?88)?01[35-9]\d{8}$/',
];
}
public function messages()
{
'mobile.regex' => 'Mobile no should be bd standard',
];
}

Related

Dutch Number & 2 Decimal Place Validation Power APP

A UK number looks like this 233.25 .
For a Dutch Number, it looks like this in the Power APP 233,25.
This works for the Power App in the UK but not in Holland, due to the comma for the decimal separator. How can I change this to get it to work? I have tried an OR statement but it does not work . ( ( TextInput.Text,"\d+(.\d{0,2})?") ) - REGEX
If(IsMatch( TextInput.Text,"\d+(.\d{0,2})?"), //justify whether meet the format
Submit(Form1), //submit the form if the result is true
Nodify("wrong format",NotificationType.Warning)) //display Notification if the result is false
You could try to format it yourself. Regardless of what the user inputs.
Left(Value(TextInput.Text),Len(Value(TextInput.Text))-2) & "," & Right(Value(TextInput.Text),2) & "."

Pandas exact str matching function?

Does pandas have a built-in string matching function for exact matches and not regex? The code below for tropical_two has a slightly higher count. Documentation tells me it does a regex search.
tropical = reviews['description'].map(lambda x: "tropical" in x).sum()
print(tropical)
tropical_two = reviews['description'].str.count("tropical").sum()
print(tropical_two)
The first way is the answer key from Kaggle but something about it seems less readable and intuitive to me compared to a .str function because when I run this it returns True instead of 2 so I am a little confused about if the answer key method is actually counting all occurrences of "tropical" and not just the first.
def in_str(text):
return "tropical" in text
in_str("tropical is tropical")
First 2 lines of dataframe:
0 Italy Aromas include tropical fruit, broom, brimston... Vulkà Bianco 87 NaN Sicily & Sardinia Etna NaN Kerin O’Keefe #kerinokeefe Nicosia 2013 Vulkà Bianco (Etna) White Blend Nicosia
1 Portugal This is ripe and fruity, a wine that is smooth... Avidagos 87 15.0 Douro NaN NaN Roger Voss #vossroger Quinta dos Avidagos 2011 Avidagos Red (Douro) Portuguese Red Quinta dos Avidagos
Notebook here, tropical code in cell #2
https://www.kaggle.com/mikexie0/exercise-summary-functions-and-maps
You may use str.count with word boundary markers to match the exact search term:
tropical_two = reviews['description'].str.count(r'\btropical\b').sum()
print(tropical_two)
There may not be the need for a separate exact API, as str.count can be used for exact matches as well.

Extracting Multiple Blocks of Similar Text

I am trying to parse a report. The following is a sample of the text that I need to parse:
7605625112 DELIVERED N 1 GORDON CONTRACTORS I SIPLAST INC Freight Priority 2000037933 $216.67 1,131 ROOFING MATERIALS
04/23/2021 02:57 PM K WRISHT N 4 CAPITOL HEIGHTS, MD ARKADELPHIA, AR Prepaid 2000037933 -$124.23 170160-00
04/27/2021 12:41 PM 2 40 20743-3706 71923 $.00 055 $.00
2 WBA HOT $62.00 0
$12.92 $92.44
$167.36
7605625123 DELIVERED N 1 SECHRIST HALL CO SIPLAST INC Freight Priority 2000037919 $476.75 871 PAIL,UN1263,PAINT,3,
04/23/2021 02:57 PM S CHAVEZ N 39 HARLINGEN, TX ARKADELPHIA, AR Prepaid 2000037919 -$378.54
04/27/2021 01:09 PM 2 479 78550 71923 $.00 085 $95.35
2 HRL HOT $62.00 21
$13.55 $98.21
$173.76
This comprised of two or more blocks that start with "[0-9]{10}\sDELIVERED" and the last currency string prior to the next block.
If I test with "(?s)([0-9]{10}\sDELIVERED)(.*)(?<=\$167.36\n)" I successfully get the first Block, but If I use "(?s)([0-9]{10}\sDELIVERED)(.*)(?<=\$\d\d\d.\d\d\n)" it grabs everything.
If someone can show me the changes that I need to make to return two or more blocks I would greatly appreciate it.
* is a greedy operator, so it will try to match as much characters as possible. See also Repetition with Star and Plus.
For fixing it, you can use this regex:
(?s)(\d{10}\sDELIVERED)((.(?!\d{10}\sDELIVERED))*)(?<=\$\d\d\d.\d\d)
in which I basically replaced .* with (.(?!\d{10}\sDELIVERED))* so that for every character it checks if it is followed or not by \d{10}\sDELIVERED.
See a demo here

extracting a location from a list with regex

I have a list like so
x=['hello#thepowerhouse.group', 'ThePowerHouse\xa0 is a part of the House of ElektroCouture', 'Our Studio is located at Bikini Berlin Terrace Level, 2nd floor Budapester Str. 46 10787 Berlin', '\xa0', 'Office:\xa0+49 30 20837551', '\xa0', '\xa0']
I want to extract the this element Our Studio is located at Bikini Berlin Terrace Level, 2nd floor Budapester Str. 46 10787 Berlin'
Since I am doing this for several sites I want to extra the element with regular expressions so it can work with others. I thought that I could grab the element by saying if the element has lower case and upper case letters, numbers , commas , and sometimes a period. This is what I attempted but it didn't work.
import re
for element in x:
if re.findall("([A-Za-z0-9,])",element)==True:
print("match")
You can split up your rule into several simple regexes and test them in sequence instead of making some monster-expression.
import re
def is_location(text):
"""Returns True if text contains digits, uppercase and lowercase characters."""
patterns = r'[0-9]', r'[a-z]', r'[A-Z]'
return all(re.search(pattern, text) for pattern in patterns)
x = [
'hello#thepowerhouse.group',
'ThePowerHouse\xa0 is a part of the House of ElektroCouture',
'Our Studio is located at Bikini Berlin Terrace Level, 2nd floor Budapester Str. 46 10787 Berlin',
'\xa0', 'Office:\xa0+49 30 20837551', '\xa0', '\xa0'
]
print(next(filter(is_location, x)))

Regex Pattern for String including newline characters

I am looking for a regex pattern that will return a match from %PDF-1.2 to and including %%EOF in the string below.
So far my patterns don't seem to work.
DOCUMENTS ACCEPTED
001//201//0E9136614////ACME 107 PTY LTD//8
**E10 End of validation report**
BDAT 4367 LAST
XSVBOUT
001XSVSEPRXXXOUT_TP.19
ZHDASCRA55 0700 8
ZCO*** TEST DATABASE ***ACME 107 PTY LTD 551824563 APTY LMSH PDF NSW 20111217 PNPC
ZIL 77000030149 Australian Securities and Investments Commission 86768265615 ZUMESOFT SOLUTIONS PTY LTD 61 buxton st north adelaide SA 5006
ZIAProprietary Company 42600 0E9136614 201 TAX INVOICE EXE 0 0E9136614201C PA 20111217 Not Subject to GST - Treasurer's Determination (Exempt Taxes, Fees and Charges)
ZTRENDRA55 5
%PDF-1.2
%????
3495
%%EOF
BDAT 11 LAST
/(?s)(%PDF-1\.2.+%%EOF)/ should solve your problem
If you are using an older flavor of regex the (?s) could be moved to the end of regex modifier like //s so.