SPONSORS:






User Tag List

Thanks Thanks:  0
Likes Likes:  0
Dislikes Dislikes:  0
Results 1 to 3 of 3
  1. #1
    Junior Member
    Join Date
    Feb 2007
    Posts
    10
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Total Downloaded
    0

    Test Complete: string & regex

    Hi

    Can anyone please provide me with some samples of working with string & regex objects using JScript. I need help with following:


    1. To use regex to check the format of phone no., email, and so on...
    Please give detailed steps as to how to create regex object, assign regex expression to it and check an input-string using this regex.

    2. To delete a part from a string.
    Eg.
    var s = "Hello Hi World!";
    From this string I want to delete the substring "Hi" and get the string "Hello World!"

    3. How to create an object provided by say .NET API like "System.Text.RegularExpressions.Regex" in Test Complete?

    Please help. I tried searching in TestComplete Help but could not find many samples related to string & regex for JScript.

    Thanks in advance.
    montap

  2. #2
    Senior Member
    Join Date
    May 2004
    Posts
    1,196
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Total Downloaded
    0

    Re: Test Complete: string & regex

    Hi Montap,

    Please see the following scripts:
    <font class="small">Code:</font><hr /><pre>//JScript
    function Test()
    {
    Log.Message(TestEMail("support@automatedqa.com"));
    Log.Message(TestPhone("+1 (702) 891-9424"));
    Log.Message(DeleteString("Hello Hi World!", "Hi "));
    }

    function TestEMail(email)
    {
    var emailPattern;

    emailPattern = new RegExp(/^[0-9A-Za-z_-]+@[0-9A-Za-z_-]+\.[A-Za-z]{1,3}$/);
    return emailPattern.test(email);
    }

    function TestPhone(phone)
    {
    var phonePattern;

    phonePattern = new RegExp(/^\+\d{1} *\(\d{1,5}\) *\d{3}-*\d{4}$/);
    return phonePattern.test(phone);
    }

    function DeleteString(string, subString)
    {
    var index;


    while (true) {
    index = string.indexOf(subString);
    if (index &lt; 0)
    break;
    string = string.substr(0, index) + string.substr(index + subString.length);
    }
    return string;
    }
    </pre><hr />

    [ QUOTE ]
    3. How to create an object provided by say .NET API like "System.Text.RegularExpressions.Regex" in Test Complete?

    [/ QUOTE ]
    You do not need to use this object since the JScript language has the built-in RegEx object. You can find documentation on this object here:
    http://msdn.microsoft.com/library/en...2c7b121534.asp
    http://msdn.microsoft.com/library/en...6f58358c0e.asp
    Best regards,
    David - SmartBear Support

  3. #3
    Junior Member
    Join Date
    Feb 2007
    Posts
    10
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Total Downloaded
    0

    Re: Test Complete: string & regex

    Thank you so much David for your reply.

    Please add such short codes in 'Help' of Test Complete, for the benefit of many newbies like me. This will save a lot of our time.

    Regards,
    Montap

 

 

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Search Engine Optimisation provided by DragonByte SEO v2.0.40 (Pro) - vBulletin Mods & Addons Copyright © 2017 DragonByte Technologies Ltd.
Resources saved on this page: MySQL 11.54%
vBulletin Optimisation provided by vB Optimise v2.7.1 (Pro) - vBulletin Mods & Addons Copyright © 2017 DragonByte Technologies Ltd.
User Alert System provided by Advanced User Tagging v3.3.0 (Pro) - vBulletin Mods & Addons Copyright © 2017 DragonByte Technologies Ltd.
vBNominate (Lite) - vBulletin Mods & Addons Copyright © 2017 DragonByte Technologies Ltd.
Feedback Buttons provided by Advanced Post Thanks / Like (Pro) - vBulletin Mods & Addons Copyright © 2017 DragonByte Technologies Ltd.
Username Changing provided by Username Change (Free) - vBulletin Mods & Addons Copyright © 2017 DragonByte Technologies Ltd.
BetaSoft Inc.
Digital Point modules: Sphinx-based search
All times are GMT -8. The time now is 11:40 PM.

Copyright BetaSoft Inc.