IP Regex and persistant datagrids

W

Wayne M J

1) I have half sorted out the IP Address reg-ex:
\d{1,3}.\d{1,3}.\d{1,3}.\d{1,3}
That works perfectly well, but I need narrow down the options. Can anyone
offer a suggestion on how to implement limitation? This is not real
critical, as I already test for the limitations in the code as it is.

2) Using the Application variable I have been able to hold object in the
past, but when I attempt to add a designed DataTable I can never access it
again.

In the Global.asax:
....//DataTable column design
Application.Add("DataTable", dt);
....

When I attempt to access it to add a row elsewhere in the code:
dr = (DataTable)(Application["DataTable"]).NewRow;

The above always return "NewRow not a Method"; as far as I knew that is how
I was meant to access the object.
 
W

Wayne M J

In Wayne M J bitched and
moaned:
1) I have half sorted out the IP Address reg-ex:
\d{1,3}.\d{1,3}.\d{1,3}.\d{1,3}
That works perfectly well, but I need narrow down the options. Can
anyone offer a suggestion on how to implement limitation? This is
not real critical, as I already test for the limitations in the code
as it is.

2) Using the Application variable I have been able to hold object in
the past, but when I attempt to add a designed DataTable I can never
access it again.

In the Global.asax:
...//DataTable column design
Application.Add("DataTable", dt);
...

When I attempt to access it to add a row elsewhere in the code:
dr = (DataTable)(Application["DataTable"]).NewRow;

The above always return "NewRow not a Method"; as far as I knew that
is how I was meant to access the object.

Solved the 2nd one:
DataTable t;
t = (DataTable)Application["DataTable];
.... //Table constructs and data
Application["DataTable"] = t;
 
J

John Saunders

Wayne M J said:
1) I have half sorted out the IP Address reg-ex:
\d{1,3}.\d{1,3}.\d{1,3}.\d{1,3}
That works perfectly well, but I need narrow down the options. Can anyone
offer a suggestion on how to implement limitation? This is not real
critical, as I already test for the limitations in the code as it is.

Wayne, if by "limitations" you mean to limit the three-digit fields to
numbers between 1 and 255, then the easiest way to do that would be in code.
I'm sure some regex wizard could do better, but normal humans should start
with the expression you've got and then continue in code.

However, you can make your life easier by using capture groups and naming
them:

(?<ip0>\d{1,3}).(?<ip1>\d{1,3}).(?<ip2>\d{1,3}).(?<ip3>\d{1,3})

This will put each field into regex.Match(string).Groups["ip<n>"], where you
can test for the value.
 
W

Wayne M J

In John Saunders bitched and
moaned:
Wayne M J said:
1) I have half sorted out the IP Address reg-ex:
\d{1,3}.\d{1,3}.\d{1,3}.\d{1,3}
That works perfectly well, but I need narrow down the options. Can
anyone offer a suggestion on how to implement limitation? This is
not real critical, as I already test for the limitations in the code
as it is.

Wayne, if by "limitations" you mean to limit the three-digit fields to
numbers between 1 and 255, then the easiest way to do that would be
in code. I'm sure some regex wizard could do better, but normal
humans should start with the expression you've got and then continue
in code.

However, you can make your life easier by using capture groups and
naming them:

(?<ip0>\d{1,3}).(?<ip1>\d{1,3}).(?<ip2>\d{1,3}).(?<ip3>\d{1,3})

This will put each field into regex.Match(string).Groups["ip<n>"],
where you can test for the value.

I did not know that was possible - I guess I should really read the manual
more often.

What I have been doing though, is just a .Split on the string, and checking
tomake sure that all fall between 0 and 255, with the except of the first
being additionally checked that it is not 0 OR 255 OR 224.

But looking at the syntax, it does make it far easier to read, and cuts back
on a few extra iterations.

Thanks.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,904
Latest member
HealthyVisionsCBDPrice

Latest Threads

Top