Thursday, 3 October 2013

Cant get my regex to validate my html form

Cant get my regex to validate my html form

I have a html form with some client validation and some server validation
(regex). But i cant get the regex to work with the html form, and it
possible to submit the form without any inputs. I have been stuck on this
for hours, argh. Any one that can understand why?
This is the HTML form

<form action="brukerinfo.php" method="post" name="kontaktskjema"
id="kontaktskjema">
<h3>Registrer din informasjon her</h3>
<div>
<label>
<span>Fornavn: (påkrevd)</span>
<input name="fornavn" id="fornavn"
placeholder="Fornavn" type="text" tabindex="1"
pattern="^[a-zA-ZæøåÆØÅ]{2,}$"
title="Fornavn er påkrevd, og må være minst 2
tegn" required autofocus>
</label>
</div>
<div>
<label>
<span>Etternavn: (påkrevd)</span>
<input name="etternavn" id="etternavn"
placeholder="Etternavn" type="text" tabindex="2"
pattern="^[a-zA-ZæøåÆØÅ]{2,}$"
title="Etternavn er påkrevd, og må være minst 2
tegn og kan ikke bestå av mellomrom" required>
</label>
</div>
<div>
<label>
<span>Email:</span>
<input name="email" id="email" type="email"
placeholder="Skriv inn din mailadresse"
tabindex="3">
</label>
</div>
<div>
<label>
<span>Telefon: (påkrevd) </span>
<input name="telefon" id="telefon"
placeholder="Skriv inn ditt telefonnummer"
type="tel" tabindex="4"
pattern="[0-9]{8}" title="Må bestå av 8 siffer"
required>
</label>
</div>
<div>
<label>
<span>DOB:</span>
<input name="fdag" id="fdag" type="date"
tabindex="5" required>
</label>
</div>
<div>
<button name="submit" type="submit"
id="kontaktskjema-submit">Send inn</button>
</div>
</form>
</div>
</div>
enter code here
And this i the regex validation,
<?
//preg_match for email
$email = $_POST['email'];
$emailregex = '[A-Z0-9._%+-]+@[A-Z0-9.-]+\\.[A-Z]{2,4}';
if(isset($_POST['email'])) {
if (!preg_match($emailregex, $email)) {
echo 'invalid email';
}
}
//validating the phone number
$telefon = $_POST ['telefon'];
$telmatch = array('98979695'
,'97969594','90807090','90908080','40908070','45674849','46573823','45343456');
if(isset($_POST['telefon'])){
if(!preg_match($telefon, $telmatch)){
echo 'invalid phone number';
}
}
//validatin the date
$fdag = $_POST['fdag'];
if(isset($_POST['fdag'])) {
if(preg_match('/(0[1-9]|[1-2][0-9]|3[0-1])-(0[1-9]|1[0-2])-^[0-9]{4}$/',
$fdag))
{
if(date(Y, time()) - date(Y,strtotime($fdag)) > 16){
echo 'invalid date';
}
else
{
echo 'you have to be at least 16';
}
}
}
?>

Wednesday, 2 October 2013

Getting maven webstart plugin to sign only the final jar file

Getting maven webstart plugin to sign only the final jar file

I followed the tutorial on the website for the plugin to the T and it
right now it not only packs and signs my final artefact, it also signs and
packs all the dependencies in the zipfile that is created. Is there any
way I could prevent it from signing and packing my dependencies?

Comparing two words from two lists in python

Comparing two words from two lists in python

I would like to compare words that are in two different lists, so for
example, I have:
['freeze','dog','difficult','answer'] and another list
['freaze','dot','dificult','anser']. I want to compare the words in this
list and give marks for incorrect letters. So, +1 for being correct, and
-1 for one letter wrong. To give some context, in a spelling test, the
first list would be answers, and the second list would be the student's
answers. How would i go about doing this?

updating and searching mysql set using php

updating and searching mysql set using php

I have a column in table which has possible values of tom,john,jerry(SET).
I have a variable that a user enter and I store it in $var and want that
at some point. I could check that if the value in $var exists in
particular row then don't update else update, How I can do this in PHP. I
have several rows like tom,john
john,jerry
I dont want `tom,john,tom`
Any help in this regard

Determining the range of values returned by Python's hash()

Determining the range of values returned by Python's hash()

I would like to map values returned by Python's hash() function to floats
in the range 0 to 1. On my system I can do this with
scale = 1.0/(2**64)
print hash(some_object)*scale+0.5
However, I know this will be different on 32-bit systems. Most likely I
will never run this code anywhere else, but still I would like to know if
there's a way to programmatically determine the maximum and minimum values
that Python's built-in hash() function can return.
(By the way the reason I'm doing this is that I'm developing a numerical
simulation in which I need to consistently generate the same pseudo-random
number from a given Numpy array. I know the built-in hash won't have the
best statistics for this, but it's fast, so it's convenient to use it for
testing purposes.)

Tuesday, 1 October 2013

ORA-02270: no matching unique or primary key for this column-list i don't know why

ORA-02270: no matching unique or primary key for this column-list i don't
know why

i tried to create a table with a foreign key to another one but i dont
know why this error keeps poping up every time i try, please help me
CREATE TABLE usuarios( username VARCHAR2(100), cedula VARCHAR2(100),
ultimoAcceso DATE, CONSTRAINT Pk PRIMARY KEY (cedula,username) ) ;
CREATE TABLE pagoPlanillas( ced VARCHAR2(100), fecha DATE, detalle
VARCHAR2(100), salario VARCHAR2(100), CONSTRAINT FK1 FOREIGN KEY(ced)
REFERENCES usuarios(cedula) ) ;

remove lines after second pattern sed

remove lines after second pattern sed

I'm looking to trim a file and I need to remove everything after the
second match (and everything before the first match).
For example Say I have this text:
xxx xxx
yyy yyy
New USB device found
xxx xxx
yyy yyy
zzz zzz
New USB device found
xxx xxx
yyy yyy
If I use : sed -i '1,/New USB device found/d' this removes everything
before the first match. which is great:
New USB device found
xxx xxx
yyy yyy
zzz zzz
New USB device found
xxx xxx
yyy yyy
But I'm only 1/2 way there, now I want to remove everything after the 2nd
match to get this result:
New USB device found
xxx xxx
yyy yyy
zzz zzz
Hence just the data for the first device. Can anyone help?