Email Validation to avoid duplicate entry within two items Apex - oracle-apex

I am having two items:
P1_email
p2_emails
Here I want to validate the email ids, the same email ids should not enter with these items.
If I enter same email id in both items, it should raise an error:
its not possible to enter the same email id in both place.

The simplest option is to create validation on P2_EMAILS item. Choose PL/SQL Function (returning error text). Code to be used:
if :P1_EMAIL = :P2_EMAILS then
return ('It is not possible to enter the same email ID in both places');
end if;
Note that this won't handle invalid e-mail addresses (such as "little#foot#gmail#com"), NULLs etc. - as I said, it is the simplest way to do what you asked.

Related

How to simplify phone_number field update Process in django including verification

Problem Description:
We have a User model where Phone number is been set as username and its unique=True,
We also have a field where to represent verified/unverified users. And we verify users by OTP verification to phone number. So now we need to add a new feature where user can replace his phone_number and then he will go to verification process and then we will change his number.
And also We need to preserve his previous number (which he already verified) until this new number is verified.
If for some reason user decides to go back without verification we delete newly added number and keeps his old number as username.
So what would be the best way to approach this problem
What I'm considering to have another Model linked with ForeignKey to User
class AlternativeNumber(models.Model):
user = User() # forignkey
number = Charfield
is_verfied = BooleanField
So we will be verifying users number and replacing his original number from his alternativenumber_set
Do you think we can simply it more. Do you think it might have some flaws or we go with a better appraoch ? thanks.
In my opinion you can add two new fields to the User class
alternative_number = CharField
is_aletrnative_verfied = BooleanField
which is really similar to your approach, but it is simpler because all the data is in one table. if a user did not verify his number then you can create a cron job that checks if the is_aletrnative_verfied and if it was false then delete whatever value is in the alternative_number just for the data to be consistent.
Hope you find this helpful!

Django Forms: How to reference existing object field values in form validation?

So I am creating a Django app which I hope will be used in my school. This means that I have users that are teachers and students, and different permissions for these accounts. I have set it up so that every accounts has a self.teacher attribute, which is a boolean. So for students accounts, self.teacher will be False, and for teachers, self.teacher will be True.
My app also contains a profile page, and this page has an edit profile feature. In my app, I want the user to be able to edit, amongst other things, their grade. Now, I have it set up so that grade can be an option of:
- 10
- 11
- 12
- N/A
Students must only be able to pick a number, while teachers are allowed to select N/A. So I want to have a form validation (which validates the grade field) that checks to see if the user submitting the form is a student, and if so, checks that they have not selected N/A. If they have selected N/A, the validation should raise an error.
Any thoughts on how to implement this using Django Forms?
If you don't want students to select a given value (here: 'N/A'), the best way is to remove this value from the choice list. In the __init__ method of the form, checks if the form instance is a student or not, and if so, remove the 'N/A' value from the choice list.

Oracle Apex email validation

I have an item to enter the email ids item_email
I need to give validation for email id item item_email that the email id should not exists already in table.
So I have to create email validation please help me to proceed on this.
You need to create a Validation (Processing tab) with type No Rows Returned, and put the following to the validation query:
select 1
from table_with_emails
where email_column = :P_EMAIL_ITEM
UPD
To check email: create a new validation (it is easier than add two checks in one) with type PL/SQL Expression, and add the following:
regexp_like (:P_EMAIL_ITEM, '^[A-Za-z]+[A-Za-z0-9.]+#[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$')
Creating a new validation also allows you to define two different error messages: when email is already exists and when it has wrong format.
Additionally, consider creating UNIQUE INDEX on e-mail column. Apex validation would do the job, but won't prevent another ways of inserting data.

Validate Email Or Number in Regex

I have a sign in form where userid is email id of users or unique id given by us i.e in integer.
So i want regex for that text box to validate email or Id.
Means.
if someone enters
abc#abc.com
or
1024
then it is valid
and if someone is entering anything other than email or integer than it should show as invalid.
Thanks...
^(?:[\w.]+#[\w.]+|\d+)$
You can try this.Though Your requirements are not very clear.See demo.
http://regex101.com/r/zU7dA5/4

Default django field value when creating from record that is being created

I have People app. I have Person model that has username field. When I add a person and that person does not have an account yet, I click the little plus sign next to the username field and I'm presented with a New User form.
That is okay.
Now I want to create users in this manner: The username should be in a form of {firstname}.{lastname}[.{serial}] fo that John Smith will have username john.smith and another John Smith would be john.smith.1.
How can I pass the firstname and lastname to the new user form? Also: How to check if there's another user with that username and append the serial number to it?
Thank you
If the first and last names are being entered (but not yet submitted) on the Person form, and you want those values to show up in the new user form view, then you'll have to:
a) use JavaScript to grab the first name and last name when the user hits that add button (the "plus button"), then
b) pass those values into a custom view that dynamically creates the {firstname}.{lastname}.[serial], then
c) assign that value to form.fields['username'].initial
When the user sees the next form, they will have the value you entered pre-populated. This logic should probably go in a custom form method (whichever form manages the username).
This strategy brings up other issues you'll have to address:
1) What if the user changes the First and Last name in the original Person form, before submitting? (#2 below might solve this)
2) Every time the first or last name are changed, you'll have to update the username on the other model
Other things to consider:
You could do this using a custom user model (docs, tutorial), and put those first and last names in the same model, which could eliminate the custom view creation, allow you to create the username dynamically in one page, and make it easier to sync them.