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
raja rameshPosted Sep 27, 2011, 3:59 AM
VulpesPosted Sep 26, 2011, 9:39 AM
raja rameshPosted Sep 24, 2011, 6:53 AM
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 ?
VulpesPosted Sep 23, 2011, 5:29 AM
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 rameshPosted Sep 23, 2011, 3:56 AM
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...
VulpesPosted Sep 22, 2011, 9:37 AM
string regExp = @"^(?=.*(a|e|i|o|u))[a-z]+$";
raja rameshPosted Sep 22, 2011, 9:25 AM
Can you tel me regex expression for name should contain vowels(aeiou).
ex: ram---true
gdfg----false
jkdkj---false
asoka----true
VulpesPosted Sep 19, 2011, 8:58 AM
string regExp = @"^CH\d+$";
Dorababu MekaPosted Sep 19, 2011, 7:21 AM
textBox1.ContextMenu = new ContextMenu();
You can also block the user to copy cut and paste the text using the following code