-3

I have to use asp.net RegularexpressionValidator to validate input from textbox. I want to reject strings that start with "My Links" or "My Urls" I have used this

   ^(?!My Links|My Urls)$

but this rejects everything. How should I write this?

3
  • 1
    What exactly should be rejected? If you really want to reject My Links|My Urls then do a string compare directly, as it is a const string Commented May 24, 2013 at 9:11
  • as I said I have to use RegularExpressionvalidator so no other choice. Commented May 24, 2013 at 9:12
  • 2
    @SpiralsWhirls show us your code.. Commented May 24, 2013 at 9:51

1 Answer 1

2

If your goal is to reject all strings that start with My Links or My Urls, then you can use lookaheads, but only if you remove the $ at the end, or only the empty string will match:

^(?!My Links|My Urls)

works as expected.

Sign up to request clarification or add additional context in comments.

11 Comments

But my guess was that .* will reject strings if it contains My Link|My Url but I need to reject stand alone My Link and MY Url..
My Links sadf rejected this string
Sorry I did not understand the $ what it does here? the last is for the end of line but did not understand the first one
'^(?!My Links$|My Questions$|My Answers$).*$' used this peice but still saving 'My Links ssss'
How exactly are you using this? Please post the entire code (in your question, not in a comment).
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.