[CLOSED] Regex possibly not working?

  1. #1

    [CLOSED] Regex possibly not working?

    Hi,

    I am working with a C# app using MVC and Ext.Net in Razor views.
    I have a text field:
    .Add(Html.X().TextField()
                    .FieldLabel("Mobile")
                    .Text(Model.mobilePhone)
                    .Width(400)
                    .Y(30)
                    .Regex(@"\+?([0-9](\s|-)*)*(ext|x)?(\s)*[0-9]+")
                    .RegexText("Valid Format: +1 800 5551212 ext3333")
                    .Name("mobilePhone")
                    .Listeners(lst => lst.Added.Handler = @"container.myMobilePhone = this;")
                )
    The user should be able to type a phone number in this field and I have provided a regex to validate the number.
    When I test this regex in a javascript regex tester, it matches the type of phone numbers I want it to.
    but When the project loads, the regex is not being activated correctly.
    If you type numbers, then letters, the field is not validated e.g. 2342 234 2sdg 234 should fail validation
    If you START with a letter e.g. "sdg2342 234 23" then it the field is highlighted and the RegexText message is displayed, otherwise it just doesn't work.

    Does anyone have any idea's what I am doing wrong here?
    Thank you in advance!
    Cheers,
    Eddie
    Last edited by Daniil; Sep 05, 2014 at 8:09 AM. Reason: Please use [CODE] tags, [CLOSED]
  2. #2
    Hi @EddieJensen,

    When I test this regex in a javascript regex tester, it matches the type of phone numbers I want it to.
    e.g. 2342 234 2sdg 234 should fail validation
    I see "true" in a alert box:
    var reg = /\+?([0-9](\s|-)*)*(ext|x)?(\s)*[0-9]+/;
    
    alert(reg.test("2342 234 2sdg 234"));
    So, the string passes the regular expression, so, it passes validation.
  3. #3
    Hi Daniil,

    Thanks for your reply. I think what you are trying to say is: the regex function is working, but my regex is wrong, because your test returns true.

    How about this example:

    var reg = /[0-9]/;
        alert(reg.test("2342 234 2sdg 234"));
    This returns true for me as well! But this regex should ONLY take numbers, it's as simple as you can get.
    It seems to me that I either don't understand the regex system here, or it's broken.

    Am I getting something wrong? Thanks for your help :)
    Last edited by Daniil; Aug 29, 2014 at 4:53 AM. Reason: Please use [CODE] tags
  4. #4
    I would try this.
    var reg = /^[\d]+$/;
    http://stackoverflow.com/questions/9...ber-only-check

Similar Threads

  1. [CLOSED] how to replace img src with Regex
    By hdsoso in forum 2.x Legacy Premium Help
    Replies: 5
    Last Post: Oct 10, 2013, 2:29 AM
  2. [CLOSED] Loading message in Multicombo and possibly in other controls
    By softmachine2011 in forum 2.x Legacy Premium Help
    Replies: 2
    Last Post: Aug 02, 2012, 2:39 PM
  3. Replies: 4
    Last Post: Apr 05, 2012, 2:38 PM
  4. This could possibly be a very simple problem.
    By RowanRishi in forum 1.x Help
    Replies: 2
    Last Post: Jul 19, 2011, 11:03 PM
  5. REGEX
    By hbbazan in forum 1.x Help
    Replies: 0
    Last Post: Jan 27, 2010, 4:09 PM

Tags for this Thread

Posting Permissions