- 2.6
- 45e-2
- 23e32
- +0.05
- -0.07e+5
So my textBox must allow these:
- Maximum one "e" or "E" letter
- "e" or "E" letter can't be at the end or at the beginning
- "+" and "-" characters are allowed
- "+" or "-" character can be only at the beginning of the number or behind the "e" OR "E" letter
- All conditions must be valid for ctrl+V, mouse paste or typing
- Maximum one "." charater before a number but not after an "e" letter.
What code do you suggest me? Thanks for all...

Dorababu MekaRank #457 · 5.5K reputationPosted Dec 28, 2012, 3:29 AM EST
Regex reg = new Regex("^[+-]?([0-9]*\\.?[0-9]+|[0-9]+\\.?[0-9]*)([eE][+-]?[0-9]+)?$");
if (reg.IsMatch(textBox1.Text))
{
}
else
{
MessageBox.Show("Invalid value");
}
Check my attachment
Dorababu MekaRank #457 · 5.5K reputationPosted Dec 28, 2012, 2:45 AM EST
Ali G51 reputationPosted Dec 28, 2012, 2:46 AM EST
Dorababu MekaRank #457 · 5.5K reputationPosted Dec 28, 2012, 2:50 AM EST
And if you would like to match with text box means
if (reg.IsMatch(youtextbox.Text))
{
///Valid
}
else
{
///Invalid
}
Dorababu MekaRank #457 · 5.5K reputationPosted Dec 28, 2012, 2:55 AM EST
Ali G51 reputationPosted Dec 28, 2012, 3:23 AM EST
MY CODES ARE HERE:
using System;
using System.Windows.Forms;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
Double DoubleKatsayi1 = 1;
Double DoubleKatsayi2 = 1;
if (listBox1.SelectedIndex == -1)
{
listBox1.SelectedIndex = 0;
}
if (listBox2.SelectedIndex == -1)
{
listBox2.SelectedIndex = 0;
}
Double DoubleSayi = Double.Parse(textBox1.Text);
switch (listBox1.SelectedItem.ToString())
{
case "meter": DoubleKatsayi1 = 1; break;
case "decimeter": DoubleKatsayi1 = 0.1; break;
case "centimeter": DoubleKatsayi1 = 0.01; break;
case "milimeter": DoubleKatsayi1 = 0.001; break;
}
switch (listBox2.SelectedItem.ToString())
{
case "meter": DoubleKatsayi2 = 1; break;
case "decimeter": DoubleKatsayi2 = 0.1; break;
case "centimeter": DoubleKatsayi2 = 0.01; break;
case "milimeter": DoubleKatsayi2 = 0.001; break;
}
Double DoubleSonuc = DoubleSayi * (DoubleKatsayi1 / DoubleKatsayi2);
textBox2.Text = DoubleSayi.ToString() + " " + listBox1.SelectedItem.ToString() + " = " + DoubleSonuc.ToString() + " " + listBox2.SelectedItem.ToString();
}
private void button2_Click(object sender, EventArgs e)
{
int index1 = listBox1.SelectedIndex;
int index2 = listBox2.SelectedIndex;
listBox1.SelectedIndex = index2;
listBox2.SelectedIndex = index1;
}
}
}
Dorababu MekaRank #457 · 5.5K reputationPosted Dec 28, 2012, 3:30 AM EST
Ali G51 reputationPosted Dec 28, 2012, 3:32 AM EST
Dorababu MekaRank #457 · 5.5K reputationPosted Dec 28, 2012, 3:34 AM EST
Dorababu MekaRank #457 · 5.5K reputationPosted Dec 28, 2012, 3:49 AM EST
Ali G51 reputationPosted Dec 28, 2012, 3:56 AM EST
=============================
Regex reg = new Regex("^[+-]?([0-9]*\\.?[0-9]+|[0-9]+\\.?[0-9]*)([eE][+-]?[0-9]+)?$");
if (reg.IsMatch(textBox1.Text))
{
}
else
{
MessageBox.Show("Invalid value");
}
==============================
code. It seems OK but I need develeop the contrent of those codes. Thanks for all..
Dorababu MekaRank #457 · 5.5K reputationPosted Dec 28, 2012, 3:59 AM EST
Ali G51 reputationPosted Dec 28, 2012, 4:08 AM EST
Dorababu MekaRank #457 · 5.5K reputationPosted Dec 28, 2012, 4:09 AM EST
Ali G51 reputationPosted Dec 28, 2012, 4:10 AM EST
Dorababu MekaRank #457 · 5.5K reputationPosted Dec 28, 2012, 4:17 AM EST
And for validating you can show a message box as per I said if it is a invalid one
Dorababu MekaRank #457 · 5.5K reputationPosted Dec 28, 2012, 4:27 AM EST
Ali G51 reputationPosted Dec 28, 2012, 4:34 AM EST
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questionsTop experts