# Watir and regexp

**URL:** <https://www.ruby-forum.com/t/watir-and-regexp/74731>\
**Category:** Ruby\
**Created:** [November 7, 2006, 10:54am UTC](https://www.ruby-forum.com/t/watir-and-regexp/74731 "2006-11-07T10:54:27Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![unknown](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/4bbf92/32.png) [@unknown](https://www.ruby-forum.com/u/unknown)\
**Post date:** [November 7, 2006, 10:54am UTC](https://www.ruby-forum.com/t/watir-and-regexp/74731/1 "2006-11-07T10:54:27Z")

</div>

We want to test a value given in a text field with a regular  
expression. We are trying to do it this way:

@browser.text\_field(:name,“vareeier”).set(“123456789”)  
@browser.text\_field(:name,“vareeier”).value.should\_equal(/[0-9]{9}/)

This is not working for us. We also tried using  
@browser.text\_field(:name,“vareeier”).value.matches(/[0-9]{9}/)  
@browser.text\_field(:name,“vareeier”).verify\_contains(/[0-9]{9}/)

None of these work.  
Help…

---

<div class="post-metadata">

**Author:** ![unknown](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/4bbf92/32.png) [@unknown](https://www.ruby-forum.com/u/unknown)\
**Post date:** [November 7, 2006, 10:54am UTC](https://www.ruby-forum.com/t/watir-and-regexp/74731/2 "2006-11-07T10:54:35Z")

</div>

removed\_email\_address@domain.invalid wrote:

> None of these work.  
> Define “work”. Have you take the step of creating a test regex that must  
> succeed, in order to eliminate syntax errors other than regex ones?

> Help…

I can’t help you with any Watir syntax issues that may be present, but  
the  
regex would be better written as:

/^\d{9}$/

This assures that nine consecutive digits are all that is present in the  
field. Your original regex only assured that nine consecutive digits  
were  
present somewhere in a field that could contain an arbitrary amount of  
other data.
