I need regx which allows only number like (1 to 9) and decimal number like (1.0 to 9.9) [Resolved]

Posted by Karthikreddy under Regular Expressions on 6/10/2013 | Points: 10 | Views : 1834 | Status : [Member] | Replies : 4
hi

i need a regular expression which allows only number like (1 to 9) and decimal number like (1.0 to 9.9)

Thanks

k@rth!k
karthikreddy08a50@gmail.com



Responses

Posted by: Raj.Trivedi on: 6/10/2013 [Member] [MVP] Starter | Points: 50

Up
0
Down

Resolved
Hello

try this

^[\d]{1,10}(\.[\d]{1,4})?$

This will check for the decimal numbers as well

For more info you can check this

http://social.msdn.microsoft.com/Forums/en-US/regexp/thread/4c75658f-5f50-4da2-bde7-d03c3534e5a2

Regard's
Raj.Trivedi
"Sharing is Caring"
Please mark as answer if your Query is resolved

Karthikreddy, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Karthikreddy on: 6/11/2013 [Member] Starter | Points: 25

Up
0
Down
hi raj

i am using javascript to validate expression

 function dayhours(sender, args) {

args.IsValid = true;
var day1 = document.getElementById('MainContent_txtday1').value;
var rgx = ^[\d]{1,10}(\.[\d]{1,4})?$ ;
if (!rgx.test(day1.value)) {
document.getElementById('MainContent_txtday1').value = "";
args.IsValid = false;
}


if we enter wrong one the txtbox will became empty problem is if we enter correct one also it's became empty can you please solve my problem

thanks

k@rth!k
karthikreddy08a50@gmail.com

Karthikreddy, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Raj.Trivedi on: 6/11/2013 [Member] [MVP] Starter | Points: 25

Up
0
Down
When it is getting empty after submitting or just by entering data on lost focus

Regard's
Raj.Trivedi
"Sharing is Caring"
Please mark as answer if your Query is resolved

Karthikreddy, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Naraayanan on: 6/18/2013 [Member] Starter | Points: 25

Up
0
Down
hI,
TRY THIS

string str = @"^(\d{10})$ |^(\d{1,8}?(\.\d{2})?)$";
Match match = Regex.Match(textBox1.Text.Trim(), str, RegexOptions.IgnoreCase);
if (!match.Success)
{
MessageBox.Show("Please enter integer with decimal");
textBox1.Focus();
}

Regards,
Lakshmi Naraayanan.S
http://dotnettechrocks.blogspot.in/
http://abaprocker.blogspot.com/

Karthikreddy, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response