Storing IP addresses & URLs & Emails

ONM

New member
Is there a way of storing IP v4 addresses and ensure validity?
Is there a way to store clickable URLs & email addresses?
Thanks
 

darren

Member
Your question is somewhat strange, storing data is the purpose of a database, are you asking how to store data in a database? It wouldn't matter if its a URL or IP or email. Can you rephrase your questions because its hard to understand if your asking for a basic understanding of how databases work or if your trying to accomplish something specific.
 

darren

Member
Upon re reading your quesiton I think i understand what you are asking, there is no way to store a "clickable" URL or email. unless you want to store the html version of a clickable link, which i would not recommend. This is entirely dependent on how your data is presented to the end user. you could tell dadabik to format every link as an html link or email if that is what you mean.

as far as the storing of IPv4 addresses and ensuring validity, i assume what you mean is "how do i validate an IPv4 address and only store it if valid?", well to answer this question i would need more information. If you simply want to validate by making sure that the IP follows the xxx.xxx.xxx.xxx format you can write a custom_validation function that would throw an error if it doesnt follow that correct format. However if your asking if its possible to ensure that an IP is a valid IP as in it points to an actual computer/server/service provider somewhere in the world, I can think of a couple ways to do that, although i am not sure how useful it would be.

Is that what you were asking?
 

ONM

New member
Thanks Darren and apologies for my scant Q. I have some, albeit dated experience with RDBMS, SQL and app dev. So my Q was about what existing column type I might use.

I have 3 additional Qs

1. How could I track down an existing custom_vaildation function to validate an IPs v4 address? It only needs to validate that the IP meets the RFC requirement, e.g. 4 dotted decimal integers values, each value 0-255 or 1-254 as appropriate, with no leading zeroes.

2. How do I tell DaDaBik to "format every link as an html link or email "

Thanks for your response
 

darren

Member
for Q 1
im not sure what you mean by "track down and existing custom_validtion function" are you asking for an example? im assuming thats what you mean. since we are writing in php, php actually already has an inbuilt function for validating ipv4 addresses using filter_var

function validateIPv4($ip) { return filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4) !== false; }

to integrate it into dadabik make sure you name the function starting with dadabik_ i.e. dadabik_validateIPv4, which i believe is still required in dadabik

for Q2

dadabik has a custom formatting functionality you can use.

an assumption will be made with the example code i provide you

1. it assumes that each value is just a link and nothing else i.e. google.com or https://google.com and it would not contain anything extra
function dadabik_link_formatting ($value){ return '<a href="' . htmlspecialchars($value) . '">' . htmlspecialchars($value) . '</a>'; }
 
Top