So I'm basically trying to create a search button.
This search is using REGEX.
I think I have it correct but it's not working, Can someone tell me how / where i've gone wrong, Not coded in AGES...
public void SearchFunction(string searchtext)
{
SupporterId();
ReferenceNumber();
ConsignmentNumber();
}
private static void SupporterId()
{
const string sId= "";
var supporterId = Regex.IsMatch(sId, @"^[A-F,S,R][0-9]{3,6}$", RegexOptions.IgnoreCase);
}
private static void ReferenceNumber()
{
const string refNumber = "";
var referenceNumber = Regex.IsMatch(refNumber, @"^[ABN158][0-9]{6,17}$", RegexOptions.IgnoreCase);
}
private static void ConsignmentNumber()
{
const string conNumber = "";
var consignmentNumber = Regex.IsMatch(conNumber, @"&[0-9]{14}$", RegexOptions.IgnoreCase);
}
}
}
Those are my Regex, And this is my code behind..
protected void CheckStateClick(object sender, EventArgs e)
{
ConsignmentSearch();
}
private void ConsignmentSearch()
{
var searchclass = new RegexMethods();
searchclass.SearchFunction(txtReferenceNumber.Text);
}
Can anyone tell me where I have gone wrong and HOW I can fix it, Please don't tell me oh your missing this an then don't tell me how to fix it.
IF you can tell me how / what needs adding to be fixed example: add this line of code here .... < >
Please and thank you.
__ THIS IS THE ERROR Test 'M:DeliveryInputSystem.Default.AddBox_Click(System.Object,System.EventArgs)' failed: Object reference not set to an instance of an object. System.NullReferenceException: Object reference not set to an instance of an object. Default.aspx.cs(113,0): at DeliveryInputSystem.Default.AddBox_Click(Object sender, EventArgs e)
I may be wrong, but it looks like you are only checking empty strings... How about checking your searchtext like this:
public void SearchFunction(string searchtext)
{
SupporterId(searchtext);
ReferenceNumber(searchtext);
ConsignmentNumber(searchtext);
}
private static void SupporterId(string sId)
{
var supporterId = Regex.IsMatch(sId, @"^[A-F,S,R][0-9]{3,6}$", RegexOptions.IgnoreCase);
}
private static void ReferenceNumber(string refNumber)
{
var referenceNumber = Regex.IsMatch(refNumber, @"^[ABN158][0-9]{6,17}$", RegexOptions.IgnoreCase);
}
private static void ConsignmentNumber(string conNumber)
{
var consignmentNumber = Regex.IsMatch(conNumber, @"&[0-9]{14}$", RegexOptions.IgnoreCase);
}
However, if I understand your code correctly, your searchtext variable only contains the txtReferenceNumber.Text text, so you should only run the ReferenceNumber(string searchtext) method on it.
You provided error text:
__ THIS IS THE ERROR Test'
M:DeliveryInputSystem.Default.AddBox_Click(System.Object,System.EventArgs)' failed:
Object reference not set to an instance of an object.
System.NullReferenceException:
Object reference not set to an instance of an object.
Default.aspx.cs(113,0): at DeliveryInputSystem.Default.AddBox_Click(Object sender, EventArgs e)
There is written cause of error: NullReferenceException
and where does it occur Default.aspx.cs(113,0)
. You need to analyze what is there, in line 113
in Default.aspx.cs
and why may it cause NullReferenceException
.
If you don't know where to start, start with documentation. According to MSDN documentation for NullReferenceException class:
A NullReferenceException exception is thrown when you try to access a member on a type whose value is null.
You have often also an example there:
1: List<String> names;
2: if (sth) names = new List<String>();
3: names.Add("Major Major Major")
If sth
is false
then no instance is assigned to names
and exception will be thrown.
So I'm basically trying to create a search button.
This search is using REGEX.
I think I have it correct but it's not working, Can someone tell me how / where i've gone wrong, Not coded in AGES...
public void SearchFunction(string searchtext)
{
SupporterId();
ReferenceNumber();
ConsignmentNumber();
}
private static void SupporterId()
{
const string sId= "";
var supporterId = Regex.IsMatch(sId, @"^[A-F,S,R][0-9]{3,6}$", RegexOptions.IgnoreCase);
}
private static void ReferenceNumber()
{
const string refNumber = "";
var referenceNumber = Regex.IsMatch(refNumber, @"^[ABN158][0-9]{6,17}$", RegexOptions.IgnoreCase);
}
private static void ConsignmentNumber()
{
const string conNumber = "";
var consignmentNumber = Regex.IsMatch(conNumber, @"&[0-9]{14}$", RegexOptions.IgnoreCase);
}
}
}
Those are my Regex, And this is my code behind..
protected void CheckStateClick(object sender, EventArgs e)
{
ConsignmentSearch();
}
private void ConsignmentSearch()
{
var searchclass = new RegexMethods();
searchclass.SearchFunction(txtReferenceNumber.Text);
}
Can anyone tell me where I have gone wrong and HOW I can fix it, Please don't tell me oh your missing this an then don't tell me how to fix it.
IF you can tell me how / what needs adding to be fixed example: add this line of code here .... < >
Please and thank you.
__ THIS IS THE ERROR Test 'M:DeliveryInputSystem.Default.AddBox_Click(System.Object,System.EventArgs)' failed: Object reference not set to an instance of an object. System.NullReferenceException: Object reference not set to an instance of an object. Default.aspx.cs(113,0): at DeliveryInputSystem.Default.AddBox_Click(Object sender, EventArgs e)
I may be wrong, but it looks like you are only checking empty strings... How about checking your searchtext like this:
public void SearchFunction(string searchtext)
{
SupporterId(searchtext);
ReferenceNumber(searchtext);
ConsignmentNumber(searchtext);
}
private static void SupporterId(string sId)
{
var supporterId = Regex.IsMatch(sId, @"^[A-F,S,R][0-9]{3,6}$", RegexOptions.IgnoreCase);
}
private static void ReferenceNumber(string refNumber)
{
var referenceNumber = Regex.IsMatch(refNumber, @"^[ABN158][0-9]{6,17}$", RegexOptions.IgnoreCase);
}
private static void ConsignmentNumber(string conNumber)
{
var consignmentNumber = Regex.IsMatch(conNumber, @"&[0-9]{14}$", RegexOptions.IgnoreCase);
}
However, if I understand your code correctly, your searchtext variable only contains the txtReferenceNumber.Text text, so you should only run the ReferenceNumber(string searchtext) method on it.
You provided error text:
__ THIS IS THE ERROR Test'
M:DeliveryInputSystem.Default.AddBox_Click(System.Object,System.EventArgs)' failed:
Object reference not set to an instance of an object.
System.NullReferenceException:
Object reference not set to an instance of an object.
Default.aspx.cs(113,0): at DeliveryInputSystem.Default.AddBox_Click(Object sender, EventArgs e)
There is written cause of error: NullReferenceException
and where does it occur Default.aspx.cs(113,0)
. You need to analyze what is there, in line 113
in Default.aspx.cs
and why may it cause NullReferenceException
.
If you don't know where to start, start with documentation. According to MSDN documentation for NullReferenceException class:
A NullReferenceException exception is thrown when you try to access a member on a type whose value is null.
You have often also an example there:
1: List<String> names;
2: if (sth) names = new List<String>();
3: names.Add("Major Major Major")
If sth
is false
then no instance is assigned to names
and exception will be thrown.
0 commentaires:
Enregistrer un commentaire