Hi,
I am working on windows applications
I am using Regex Expressions, I can write regex expression for only digits but my requirement is first to letters are "CH" after my textbox has to accept only digits
Ex: CH4324324
CH11111
CH789798......
In this scenario I dont want to change value CH as prefix of that box
user has to change only after this prefix so any one can tel me regex expression.
problem 2:
I have written to handle unwanted data in keypress events like following way
Regex regex = new Regex((sender as RadMaskedEditBoxElement).Mask);
if (!regex.IsMatch(e.KeyChar.ToString()))
e.Handled = true;
{
return;
}
But its working for only when I press key from keyboard but its not working for copy-paste and cut-paste and paste by using mouse but I want to handle unwanted data for paste
How to do this ?
Any one can tel me reply for above two questions....
Loading

Dorababu MekaRank #457 · 5.5K reputationPosted Sep 19, 2011, 3:21 AM EDT
textBox1.ContextMenu = new ContextMenu();
You can also block the user to copy cut and paste the text using the following code
VulpesRank #55 · 29.2K reputationPosted Sep 19, 2011, 4:58 AM EDT
string regExp = @"^CH\d+$";
raja ramesh46 reputationPosted Sep 22, 2011, 5:25 AM EDT
Can you tel me regex expression for name should contain vowels(aeiou).
ex: ram---true
gdfg----false
jkdkj---false
asoka----true
VulpesRank #55 · 29.2K reputationPosted Sep 22, 2011, 5:37 AM EDT
string regExp = @"^(?=.*(a|e|i|o|u))[a-z]+$";
raja ramesh46 reputationPosted Sep 22, 2011, 11:56 PM EDT
Your expression is useful to me but
I have some mandatory fields and some non mandatory fields so your expression is suitable for only mandatory fields. how to do for non madatory filds ?
2)I have writen expression to handle for morethan 3 characters are same sequently as following
@"^(?!.*(?'letter'[a-z])\k'letter'{2,})[a-z,]+$"
Can you write expression for combination of this expression and my previous case(aeiou).
Thanks for you advance...
VulpesRank #55 · 29.2K reputationPosted Sep 23, 2011, 1:29 AM EDT
string regExp = @"^(|(?=.*(a|e|i|o|u))[a-z]+)$";
To combine the expression that disallows 3 or more consecutive identical letters with the above but allow commas as well would be:
string regExp = @"^(|(?!.*(?'letter'[a-z])\k'letter'{2,})(?=.*(a|e|i|o|u))[a-z,]+)$";
The mandatory version of that would be:
string regExp = @"^(?!.*(?'letter'[a-z])\k'letter'{2,})(?=.*(a|e|i|o|u))[a-z,]+$";
raja ramesh46 reputationPosted Sep 24, 2011, 2:53 AM EDT
but this is failed in keypress event .
Regex regex = new Regex((sender as RadMaskedEditBoxElement).Mask);
if (!regex.IsMatch(e.KeyChar.ToString()))
{
e.Handled = true;
return;
}
if (TextLength> 0)
{
if (TextLength <= CursorPosition)
{
newText = radMaskedEditBoxText + e.KeyChar.ToString();
}
else if(...)
...
if (!regex.IsMatch(newText))
{
e.Handled = true;
return;
}
}
(This is failed because I think in that expression contains vowels condition).
Is there any chance to handle unwated keys in keypress event by using this expression ?
VulpesRank #55 · 29.2K reputationPosted Sep 26, 2011, 5:39 AM EDT
raja ramesh46 reputationPosted Sep 26, 2011, 11:59 PM EDT