# Regex pattern for mobile number not working properly

**URL:** <https://forum.rasa.com/t/regex-pattern-for-mobile-number-not-working-properly/935>\
**Category:** Rasa Open Source\
**Created:** [September 7, 2018, 7:36am UTC](https://forum.rasa.com/t/regex-pattern-for-mobile-number-not-working-properly/935 "2018-09-07T07:36:16Z")\
**Posts on this page:** 19\
**Page:** 1

<div class="post-metadata">

**Author:** ![NikhilBansal21](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.rasa.com/nikhilbansal21/32/418_2.png) [@NikhilBansal21](https://forum.rasa.com/u/NikhilBansal21)\
**Post date:** [September 7, 2018, 7:36am UTC](https://forum.rasa.com/t/regex-pattern-for-mobile-number-not-working-properly/935/1 "2018-09-07T07:36:16Z")

</div>

I have added this regex pattern in my training data file

> \[1\][0-9]{9}$

This regex picks up possible outcomes like indian mobile numbers but the issue is it is not limiting the digit to 10 i.e if i enter like 12345 or even 123 it is taking it into slots also i have tested this regex here

> [https://regex101.com/](https://regex101.com/)

pattern is working fine but i am facing issue with my bot

* * *

1. 789

---

<div class="post-metadata">

**Author:** ![akelad](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.rasa.com/akelad/32/69_2.png) [@akelad](https://forum.rasa.com/u/akelad)\
**Post date:** [September 7, 2018, 12:18pm UTC](https://forum.rasa.com/t/regex-pattern-for-mobile-number-not-working-properly/935/2 "2018-09-07T12:18:13Z")

</div>

Can you post the regex section of your training data file?

---

<div class="post-metadata">

**Author:** ![NikhilBansal21](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.rasa.com/nikhilbansal21/32/418_2.png) [@NikhilBansal21](https://forum.rasa.com/u/NikhilBansal21)\
**Post date:** [September 7, 2018, 12:20pm UTC](https://forum.rasa.com/t/regex-pattern-for-mobile-number-not-working-properly/935/3 "2018-09-07T12:20:06Z")

</div>

> ```
> "regex_features": [
> {
> "name": "email",
> "pattern": "^([a-zA-Z0-9_\\-\\.]+)@([a-zA-Z0-9_\\-\\.]+)\\.([a-zA-Z]{2,5})$"
> },
> {
> "name": "IncidentID",
> "pattern": "(?i)(SR)[0-9]*"
> },
> {
> "name": "empCode",
> "pattern": "\\b\\d{8}\\b"
> },
> {
> "name": "otp",
> "pattern": "\\b\\d{6}\\b"
> },
> {
> "name": "MobNumberInt",
> "pattern": "[(+]*[0-9]{10}[()+. -]*"
> }
> ],
> 
> ```

---

<div class="post-metadata">

**Author:** ![NikhilBansal21](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.rasa.com/nikhilbansal21/32/418_2.png) [@NikhilBansal21](https://forum.rasa.com/u/NikhilBansal21)\
**Post date:** [September 7, 2018, 12:25pm UTC](https://forum.rasa.com/t/regex-pattern-for-mobile-number-not-working-properly/935/4 "2018-09-07T12:25:06Z")

</div>

i am facing issue with mobile number regex pattern their are two mentioned both are facing this issue

---

<div class="post-metadata">

**Author:** ![akelad](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.rasa.com/akelad/32/69_2.png) [@akelad](https://forum.rasa.com/u/akelad)\
**Post date:** [September 7, 2018, 12:29pm UTC](https://forum.rasa.com/t/regex-pattern-for-mobile-number-not-working-properly/935/5 "2018-09-07T12:29:10Z")

</div>

I’m confused, I thought you said there was a problem with the number regex?

---

<div class="post-metadata">

**Author:** ![NikhilBansal21](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.rasa.com/nikhilbansal21/32/418_2.png) [@NikhilBansal21](https://forum.rasa.com/u/NikhilBansal21)\
**Post date:** [September 7, 2018, 12:33pm UTC](https://forum.rasa.com/t/regex-pattern-for-mobile-number-not-working-properly/935/6 "2018-09-07T12:33:50Z")

</div>

i have mentioned mobile numbers above, i want my bot to accept mobile numbers not random numbers like 123456 or anything of that sort! right now bot is accepting any numeric value into the slot

---

<div class="post-metadata">

**Author:** ![akelad](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.rasa.com/akelad/32/69_2.png) [@akelad](https://forum.rasa.com/u/akelad)\
**Post date:** [September 10, 2018, 8:36am UTC](https://forum.rasa.com/t/regex-pattern-for-mobile-number-not-working-properly/935/7 "2018-09-10T08:36:43Z")

</div>

Can you also post what your training data looks like? Do you have any other shorter numbers that are present in it as well (doesn’t have to be the same entity)?

---

<div class="post-metadata">

**Author:** ![NikhilBansal21](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.rasa.com/nikhilbansal21/32/418_2.png) [@NikhilBansal21](https://forum.rasa.com/u/NikhilBansal21)\
**Post date:** [September 10, 2018, 8:37am UTC](https://forum.rasa.com/t/regex-pattern-for-mobile-number-not-working-properly/935/8 "2018-09-10T08:37:53Z")

</div>

no in my training data for fetching mobile number i dont have less that 10 digit input.

---

<div class="post-metadata">

**Author:** ![NikhilBansal21](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.rasa.com/nikhilbansal21/32/418_2.png) [@NikhilBansal21](https://forum.rasa.com/u/NikhilBansal21)\
**Post date:** [September 10, 2018, 8:50am UTC](https://forum.rasa.com/t/regex-pattern-for-mobile-number-not-working-properly/935/9 "2018-09-10T08:50:27Z")

</div>

training data - [https://gist.github.com/NikhilBansal21/98028418102128453593a30885d38e1f](https://gist.github.com/NikhilBansal21/98028418102128453593a30885d38e1f)

---

<div class="post-metadata">

**Author:** ![akelad](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.rasa.com/akelad/32/69_2.png) [@akelad](https://forum.rasa.com/u/akelad)\
**Post date:** [September 12, 2018, 7:47am UTC](https://forum.rasa.com/t/regex-pattern-for-mobile-number-not-working-properly/935/10 "2018-09-12T07:47:10Z")

</div>

Ok so the thing is it doesn’t just pay attention to the actual word, but also the context. This is why it might accept shorter numbers too. Also you do have a short number as a mobile number entity towards the bottom of your training data. I saw that you have a lot of different numbers that you extract as different entities, my suggestion would be just to extract these with duckling and then store them in slots with a custom action. That way you can validate them to see if they’re in the correct format too

---

<div class="post-metadata">

**Author:** ![NikhilBansal21](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.rasa.com/nikhilbansal21/32/418_2.png) [@NikhilBansal21](https://forum.rasa.com/u/NikhilBansal21)\
**Post date:** [September 12, 2018, 12:30pm UTC](https://forum.rasa.com/t/regex-pattern-for-mobile-number-not-working-properly/935/11 "2018-09-12T12:30:29Z")

</div>

yes i added less digits because every time i enter like -

U- my employee id is 9999852419 (a mobile number string)

My bot picks up mobile number intent in this case which i don’t want my bot to do. even if user enters a mobile number in case of employee id or otp i want my bot to process it and guide user that input is wrong. Yes you are right i want it to handle at that context itself !

---

<div class="post-metadata">

**Author:** ![NikhilBansal21](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.rasa.com/nikhilbansal21/32/418_2.png) [@NikhilBansal21](https://forum.rasa.com/u/NikhilBansal21)\
**Post date:** [September 14, 2018, 6:10am UTC](https://forum.rasa.com/t/regex-pattern-for-mobile-number-not-working-properly/935/12 "2018-09-14T06:10:32Z")

</div>

i have implemented duckling

> pipeline:
> 
> - name: “tokenizer\_whitespace”
> - name: “intent\_entity\_featurizer\_regex”
> - name: “ner\_duckling\_http”
> - name: “ner\_synonyms”
> - name: “intent\_featurizer\_count\_vectors”
> - name: “intent\_classifier\_tensorflow\_embedding” intent\_tokenization\_flag: true intent\_split\_symbol: “+”

after using this bot is not extracting entities at all

---

<div class="post-metadata">

**Author:** ![souvikg10](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.rasa.com/souvikg10/32/93_2.png) [@souvikg10](https://forum.rasa.com/u/souvikg10)\
**Post date:** [September 14, 2018, 9:04am UTC](https://forum.rasa.com/t/regex-pattern-for-mobile-number-not-working-properly/935/13 "2018-09-14T09:04:09Z")

</div>

you need to provide the server for duckling

> [@How to use duckling in pipeline](https://forum.rasa.com/t/how-to-use-duckling-in-pipeline/91/7):
>
> pipeline: - name: “tokenizer\_whitespace” - name: “intent\_entity\_featurizer\_regex” - name: “ner\_crf” - name: “ner\_synonyms” - name: “intent\_featurizer\_count\_vectors” - name: “intent\_classifier\_tensorflow\_embedding” intent\_tokenization\_flag: true intent\_split\_symbol: “+” - name: “ner\_duckling\_http” url: “[http://0.0.0.0:8000](http://0.0.0.0:8000)” locale: “da\_DK” dimensions: [“time”]

---

<div class="post-metadata">

**Author:** ![NikhilBansal21](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.rasa.com/nikhilbansal21/32/418_2.png) [@NikhilBansal21](https://forum.rasa.com/u/NikhilBansal21)\
**Post date:** [September 14, 2018, 9:05am UTC](https://forum.rasa.com/t/regex-pattern-for-mobile-number-not-working-properly/935/14 "2018-09-14T09:05:18Z")

</div>

what server ?? the port where my core runs?

---

<div class="post-metadata">

**Author:** ![souvikg10](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.rasa.com/souvikg10/32/93_2.png) [@souvikg10](https://forum.rasa.com/u/souvikg10)\
**Post date:** [September 14, 2018, 9:07am UTC](https://forum.rasa.com/t/regex-pattern-for-mobile-number-not-working-properly/935/15 "2018-09-14T09:07:09Z")

</div>

duckling server

> **[Components](https://rasa.com/docs/rasa/components/)**

---

<div class="post-metadata">

**Author:** ![NikhilBansal21](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.rasa.com/nikhilbansal21/32/418_2.png) [@NikhilBansal21](https://forum.rasa.com/u/NikhilBansal21)\
**Post date:** [September 14, 2018, 11:05am UTC](https://forum.rasa.com/t/regex-pattern-for-mobile-number-not-working-properly/935/16 "2018-09-14T11:05:02Z")

</div>

here it says that

> To use this component you need to run a duckling server. The easiest option is to spin up a docker container using `docker run -p 8000:8000 rasa/duckling` .

How can i run it without docker?

---

<div class="post-metadata">

**Author:** ![souvikg10](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.rasa.com/souvikg10/32/93_2.png) [@souvikg10](https://forum.rasa.com/u/souvikg10)\
**Post date:** [September 14, 2018, 11:20am UTC](https://forum.rasa.com/t/regex-pattern-for-mobile-number-not-working-properly/935/17 "2018-09-14T11:20:21Z")

</div>

> **[GitHub - facebook/duckling: Language, engine, and tooling for expressing,...](https://github.com/facebook/duckling)**
>
> Language, engine, and tooling for expressing, testing, and evaluating composable language rules on input strings. - GitHub - facebook/duckling: Language, engine, and tooling for expressing, testing...

the installation instructions are here

---

<div class="post-metadata">

**Author:** ![NikhilBansal21](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.rasa.com/nikhilbansal21/32/418_2.png) [@NikhilBansal21](https://forum.rasa.com/u/NikhilBansal21)\
**Post date:** [September 14, 2018, 11:35am UTC](https://forum.rasa.com/t/regex-pattern-for-mobile-number-not-working-properly/935/18 "2018-09-14T11:35:54Z")

</div>

thanks 🙂

---

<div class="post-metadata">

**Author:** ![Akhil](https://avatars.discourse-cdn.com/v4/letter/a/7ab992/32.png) [@Akhil](https://forum.rasa.com/u/Akhil)\
**Post date:** [August 26, 2020, 2:57am UTC](https://forum.rasa.com/t/regex-pattern-for-mobile-number-not-working-properly/935/19 "2020-08-26T02:57:28Z")

</div>

Hi @NikhilBansal21. I’m facing the same issue. Were you able to solve it?
