- 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 MekaPosted Dec 28, 2012, 8:29 AM
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
Ali GPosted Dec 28, 2012, 9:34 AM
Dorababu MekaPosted Dec 28, 2012, 9:27 AM
Dorababu MekaPosted Dec 28, 2012, 9:17 AM
And for validating you can show a message box as per I said if it is a invalid one
Ali GPosted Dec 28, 2012, 9:10 AM
Dorababu MekaPosted Dec 28, 2012, 9:09 AM
Ali GPosted Dec 28, 2012, 9:08 AM
Dorababu MekaPosted Dec 28, 2012, 8:59 AM
Ali GPosted Dec 28, 2012, 8:56 AM
=============================
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 MekaPosted Dec 28, 2012, 8:49 AM
Dorababu MekaPosted Dec 28, 2012, 8:34 AM
Ali GPosted Dec 28, 2012, 8:32 AM
Dorababu MekaPosted Dec 28, 2012, 8:30 AM
Ali GPosted Dec 28, 2012, 8:23 AM
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 MekaPosted Dec 28, 2012, 7:55 AM
Dorababu MekaPosted Dec 28, 2012, 7:50 AM
And if you would like to match with text box means
if (reg.IsMatch(youtextbox.Text))
{
///Valid
}
else
{
///Invalid
}
Ali GPosted Dec 28, 2012, 7:46 AM
Dorababu MekaPosted Dec 28, 2012, 7:45 AM